CVS Update: xmlpull-api-v1/src/java/api/org/xmlpull/v1

Aleksander Andrzej Slominski <[email protected]> Tue, 20 May 2003 05:03:13 -0500 (EST)
Newsgroups gmane.text.xml.xmlpull.devel
Message-ID <[email protected]>
aslom       03/05/20 05:03:13

  Modified:    addons/java/sax2_driver/src/org/xmlpull/v1/sax2 Driver.java
               addons/java/wrapper/src/org/xmlpull/v1/wrapper/classic
                        StaticXmlSerializerWrapper.java
               src/java/api/org/xmlpull/v1 XmlPullParserFactory.java
  Log:
  applied set of optimizations suggested by Ville Skyttä
  
  Revision  Changes    Path
  1.4       +19 -19    xmlpull-api-v1/addons/java/sax2_driver/src/org/xmlpull/v1/sax2/Driver.java
  
  Index: Driver.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/addons/java/sax2_driver/src/org/xmlpull/v1/sax2/Driver.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -t -w -r1.3 -r1.4
  --- Driver.java	25 Feb 2003 20:08:12 -0000	1.3
  +++ Driver.java	20 May 2003 10:03:12 -0000	1.4
  @@ -77,7 +77,7 @@
       /**
        */
       public Driver() throws XmlPullParserException {
  -        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  +        final XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
           factory.setNamespaceAware(true);
           pp = factory.newPullParser();
       }
  @@ -92,7 +92,7 @@
       public String getURI(int index) { return pp.getAttributeNamespace(index); }
       public String getLocalName(int index) { return pp.getAttributeName(index); }
       public String getQName(int index) {
  -        String prefix = pp.getAttributePrefix(index);
  +        final String prefix = pp.getAttributePrefix(index);
           if(prefix != null) {
               return prefix+':'+pp.getAttributeName(index);
           } else {
  @@ -273,11 +273,11 @@
           systemId = source.getSystemId();
           contentHandler.setDocumentLocator(this);
   
  -        Reader reader = source.getCharacterStream();
  +        final Reader reader = source.getCharacterStream();
           try {
               if (reader == null) {
                   InputStream stream = source.getByteStream();
  -                String encoding = source.getEncoding();
  +                final String encoding = source.getEncoding();
   
                   if (stream == null) {
                       systemId = source.getSystemId();
  @@ -289,13 +289,13 @@
                       }
                       // NOTE: replace with Connection to run in J2ME environment
                       try {
  -                        URL url = new URL(systemId);
  +                        final URL url = new URL(systemId);
                           stream = url.openStream();
                       } catch (MalformedURLException nue) {
                           try {
                               stream = new FileInputStream(systemId);
                           } catch (FileNotFoundException fnfe) {
  -                            SAXParseException saxException = new SAXParseException(
  +                            final SAXParseException saxException = new SAXParseException(
                                   "could not open file with systemId "+systemId, this, fnfe);
                               errorHandler.fatalError(saxException);
                               return;
  @@ -307,7 +307,7 @@
                   pp.setInput(reader);
               }
           } catch (XmlPullParserException ex)  {
  -            SAXParseException saxException = new SAXParseException(
  +            final SAXParseException saxException = new SAXParseException(
                   "parsing initialization error: "+ex, this, ex);
               //if(DEBUG) ex.printStackTrace();
               errorHandler.fatalError(saxException);
  @@ -321,14 +321,14 @@
               pp.next();
               // it should be start tag...
               if(pp.getEventType() != XmlPullParser.START_TAG) {
  -                SAXParseException saxException = new SAXParseException(
  +                final SAXParseException saxException = new SAXParseException(
                       "expected start tag not"+pp.getPositionDescription(), this);
                   //throw saxException;
                   errorHandler.fatalError(saxException);
                   return;
               }
           } catch (XmlPullParserException ex)  {
  -            SAXParseException saxException = new SAXParseException(
  +            final SAXParseException saxException = new SAXParseException(
                   "parsing initialization error: "+ex, this, ex);
               //ex.printStackTrace();
               errorHandler.fatalError(saxException);
  @@ -351,14 +351,14 @@
   
       public void parseSubTree(XmlPullParser pp) throws SAXException, IOException {
           this.pp = pp;
  -        boolean namespaceAware = pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES);
  +        final boolean namespaceAware = pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES);
           try {
               if(pp.getEventType() != XmlPullParser.START_TAG) {
                   throw new SAXException(
                       "start tag must be read before skiping subtree"+pp.getPositionDescription());
               }
  -            int[] holderForStartAndLength = new int[2];
  -            StringBuffer rawName = new StringBuffer();
  +            final int[] holderForStartAndLength = new int[2];
  +            final StringBuffer rawName = new StringBuffer(16);
               String prefix = null;
               String name = null;
               int level = pp.getDepth() - 1;
  @@ -369,11 +369,11 @@
                   switch(type) {
                       case XmlPullParser.START_TAG:
                           if(namespaceAware) {
  -                            int depth = pp.getDepth() - 1;
  -                            int countPrev =
  +                            final int depth = pp.getDepth() - 1;
  +                            final int countPrev =
                                   (level > depth) ? pp.getNamespaceCount(depth) : 0;
                               //int countPrev = pp.getNamespaceCount(pp.getDepth() - 1);
  -                            int count = pp.getNamespaceCount(depth + 1);
  +                            final int count = pp.getNamespaceCount(depth + 1);
                               for (int i = countPrev; i < count; i++)
                               {
                                   contentHandler.startPrefixMapping(
  @@ -401,7 +401,7 @@
   
                           break;
                       case XmlPullParser.TEXT:
  -                        char[] chars = pp.getTextCharacters(holderForStartAndLength);
  +                        final char[] chars = pp.getTextCharacters(holderForStartAndLength);
                           contentHandler.characters(chars,
                                                     holderForStartAndLength[0], //start
                                                     holderForStartAndLength[1] //len
  @@ -423,8 +423,8 @@
                                                         prefix != null ? name : rawName.toString()
                                                        );
                               // when entering show prefixes for all levels!!!!
  -                            int depth = pp.getDepth();
  -                            int countPrev =
  +                            final int depth = pp.getDepth();
  +                            final int countPrev =
                                   (level > depth) ? pp.getNamespaceCount(pp.getDepth()) : 0;
                               int count = pp.getNamespaceCount(pp.getDepth() - 1);
                               // undeclare them in reverse order
  @@ -448,7 +448,7 @@
                   type = pp.next();
               } while(pp.getDepth() > level);
           } catch (XmlPullParserException ex)  {
  -            SAXParseException saxException = new SAXParseException("parsing error: "+ex, this, ex);
  +            final SAXParseException saxException = new SAXParseException("parsing error: "+ex, this, ex);
               ex.printStackTrace();
               errorHandler.fatalError(saxException);
           }
  
  
  
  1.7       +3 -3      xmlpull-api-v1/addons/java/wrapper/src/org/xmlpull/v1/wrapper/classic/StaticXmlSerializerWrapper.java
  
  Index: StaticXmlSerializerWrapper.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/addons/java/wrapper/src/org/xmlpull/v1/wrapper/classic/StaticXmlSerializerWrapper.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -t -w -r1.6 -r1.7
  --- StaticXmlSerializerWrapper.java	19 May 2003 14:43:03 -0000	1.6
  +++ StaticXmlSerializerWrapper.java	20 May 2003 10:03:13 -0000	1.7
  @@ -253,9 +253,9 @@
   
       private void writeStartTag(XmlPullParser pp) throws XmlPullParserException, IOException {
           if (!pp.getFeature (XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES)) {
  -            for (int i = pp.getNamespaceCount (pp.getDepth ()-1);
  -                 i < pp.getNamespaceCount (pp.getDepth ()); i++)
  -            {
  +            int nsStart = pp.getNamespaceCount(pp.getDepth()-1);
  +            int nsEnd = pp.getNamespaceCount(pp.getDepth());
  +            for (int i = nsStart; i < nsEnd; i++) {
                   String prefix = pp.getNamespacePrefix(i);
                   String ns = pp.getNamespaceUri(i);
                   setPrefix(prefix, ns);
  
  
  
  1.25      +13 -13    xmlpull-api-v1/src/java/api/org/xmlpull/v1/XmlPullParserFactory.java
  
  Index: XmlPullParserFactory.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/api/org/xmlpull/v1/XmlPullParserFactory.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -b -t -w -r1.24 -r1.25
  --- XmlPullParserFactory.java	8 Apr 2003 19:35:31 -0000	1.24
  +++ XmlPullParserFactory.java	20 May 2003 10:03:13 -0000	1.25
  @@ -175,19 +175,19 @@
           if (parserClasses.size() == 0) throw new XmlPullParserException
                   ("No valid parser classes found in "+classNamesLocation);
   
  -        StringBuffer issues = new StringBuffer ();
  +        final StringBuffer issues = new StringBuffer ();
   
           for (int i = 0; i < parserClasses.size (); i++) {
  -            Class ppClass = (Class) parserClasses.elementAt (i);
  +            final Class ppClass = (Class) parserClasses.elementAt (i);
               try {
  -                XmlPullParser pp = (XmlPullParser) ppClass.newInstance();
  +                final XmlPullParser pp = (XmlPullParser) ppClass.newInstance();
                   //            if( ! features.isEmpty() ) {
                   //Enumeration keys = features.keys();
                   // while(keys.hasMoreElements()) {
   
                   for (Enumeration e = features.keys (); e.hasMoreElements ();) {
  -                    String key = (String) e.nextElement();
  -                    Boolean value = (Boolean) features.get(key);
  +                    final String key = (String) e.nextElement();
  +                    final Boolean value = (Boolean) features.get(key);
                       if(value != null && value.booleanValue()) {
                           pp.setFeature(key, true);
                       }
  @@ -224,12 +224,12 @@
                   ("No valid serializer classes found in "+classNamesLocation);
           }
   
  -        StringBuffer issues = new StringBuffer ();
  +        final StringBuffer issues = new StringBuffer ();
   
           for (int i = 0; i < serializerClasses.size (); i++) {
  -            Class ppClass = (Class) serializerClasses.elementAt (i);
  +            final Class ppClass = (Class) serializerClasses.elementAt (i);
               try {
  -                XmlSerializer ser = (XmlSerializer) ppClass.newInstance();
  +                final XmlSerializer ser = (XmlSerializer) ppClass.newInstance();
   
                   //                for (Enumeration e = features.keys (); e.hasMoreElements ();) {
                   //                    String key = (String) e.nextElement();
  @@ -278,10 +278,10 @@
                   if (is == null) throw new XmlPullParserException
                           ("resource not found: "+RESOURCE_NAME
                                +" make sure that parser implementing XmlPull API is available");
  -                StringBuffer sb = new StringBuffer();
  +                final StringBuffer sb = new StringBuffer();
   
                   while (true) {
  -                    int ch = is.read();
  +                    final int ch = is.read();
                       if (ch < 0) break;
                       else if (ch > ' ')
                           sb.append((char) ch);
  @@ -300,15 +300,15 @@
           }
   
           XmlPullParserFactory factory = null;
  -        Vector parserClasses = new Vector ();
  -        Vector serializerClasses = new Vector ();
  +        final Vector parserClasses = new Vector ();
  +        final Vector serializerClasses = new Vector ();
           int pos = 0;
   
           while (pos < classNames.length ()) {
               int cut = classNames.indexOf (',', pos);
   
               if (cut == -1) cut = classNames.length ();
  -            String name = classNames.substring (pos, cut);
  +            final String name = classNames.substring (pos, cut);
   
               Class candidate = null;
               Object instance = null;
  
  
  


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get A Free Psychic Reading!
Your Online Answer To Life's Important Questions.
http://us.click.yahoo.com/aM1XQD/od7FAA/uetFAA/2U_rlB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/