tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-tapestry/framework/src/org/apache/tapestry/parse TemplateParser.java
Date Tue, 18 Mar 2003 20:54:42 GMT
hlship      2003/03/18 12:54:42

  Modified:    framework/src/org/apache/tapestry/parse TemplateParser.java
  Log:
  Slight optimization on creation of Location objects.
  
  Revision  Changes    Path
  1.4       +36 -7     jakarta-tapestry/framework/src/org/apache/tapestry/parse/TemplateParser.java
  
  Index: TemplateParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/parse/TemplateParser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TemplateParser.java	15 Mar 2003 21:22:19 -0000	1.3
  +++ TemplateParser.java	18 Mar 2003 20:54:42 -0000	1.4
  @@ -271,6 +271,13 @@
        **/
   
       private Location _templateLocation;
  +    
  +    /**
  +     *  Location with in the resource for the current line.
  +     * 
  +     **/
  +    
  +    private Location _currentLocation;
   
       /**
        *  Local reference to the template data that is to be parsed.
  @@ -423,6 +430,7 @@
               _templateData = null;
               _resourceLocation = null;
               _templateLocation = null;
  +            _currentLocation = null;
               _stack.clear();
               _tokens.clear();
               _attributes.clear();
  @@ -716,7 +724,7 @@
                                   tagName,
                                   Integer.toString(_line),
                                   attributeName),
  -                            new Location(_resourceLocation, _line));
  +                            getCurrentLocation());
   
                       // Ignore whitespace between '=' and the attribute value.  Also, look
                       // for initial quote.
  @@ -986,7 +994,7 @@
               addOpenToken(tagName, jwcId, type, startLocation);
   
               if (emptyTag)
  -                _tokens.add(new CloseToken(tagName, new Location(_resourceLocation, _line)));
  +                _tokens.add(new CloseToken(tagName, getCurrentLocation()));
           }
   
           advance();
  @@ -1126,6 +1134,8 @@
           int length = _templateData.length;
           int startLine = _line;
   
  +		Location startLocation = getCurrentLocation();
  +		
           _cursor += CLOSE_TAG.length;
   
           int tagStart = _cursor;
  @@ -1137,7 +1147,7 @@
                       Tapestry.getString(
                           "TemplateParser.incomplete-close-tag",
                           Integer.toString(startLine)),
  -                    new Location(_resourceLocation, startLine));
  +                    startLocation);
   
               char ch = _templateData[_cursor];
   
  @@ -1168,7 +1178,7 @@
                               Integer.toString(startLine),
                               tag._tagName,
                               Integer.toString(tag._line)}),
  -                    new Location(_resourceLocation, startLine));
  +                    startLocation);
   
               stackPos--;
           }
  @@ -1179,7 +1189,7 @@
                       "TemplateParser.unmatched-close-tag",
                       tagName,
                       Integer.toString(startLine)),
  -                new Location(_resourceLocation, startLine));
  +                startLocation);
   
           // Special case for the content tag
   
  @@ -1199,7 +1209,7 @@
           {
               addTextToken(cursorStart - 1);
   
  -            _tokens.add(new CloseToken(tagName, new Location(_resourceLocation, _line)));
  +            _tokens.add(new CloseToken(tagName, getCurrentLocation()));
           }
           else
           {
  @@ -1254,6 +1264,7 @@
           if (ch == '\n')
           {
               _line++;
  +            _currentLocation = null;
               return;
           }
   
  @@ -1262,6 +1273,7 @@
           if (ch == '\r')
           {
               _line++;
  +            _currentLocation = null;
   
               if (_cursor < length && _templateData[_cursor] == '\n')
                   _cursor++;
  @@ -1418,5 +1430,22 @@
               return false;
   
           return value.equalsIgnoreCase("true");
  +    }
  +    
  +    /**
  +     *  Gets the current location within the file.  This allows the location to be
  +     *  created only as needed, and multiple objects on the same line can share
  +     *  the same Location instance.
  +     * 
  +     *  @since 2.4
  +     * 
  +     **/
  +    
  +    protected Location getCurrentLocation()
  +    {
  +    	if (_currentLocation == null)
  +    	_currentLocation = new Location(_resourceLocation, _line);
  +    	
  +    	return _currentLocation;
       }
   }
  
  
  

Mime
View raw message