Skip to content

Commit

Permalink
#1680 Avoid eager initialization of Scope objects
Browse files Browse the repository at this point in the history
  • Loading branch information
whitingjr authored and lukasj committed Jan 18, 2023
1 parent 7e7f0d0 commit 0f9b768
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,6 @@ public String getNamespaceURI(String prefix) {
*/
private int scopeTop=0;

{
for( int i=0; i<scopes.length; i++ )
scopes[i] = new Scope(this);
}

/**
* Starts a new packing scope.
*
Expand Down Expand Up @@ -1036,8 +1031,11 @@ public void startScope(int frameSize) {
*/
public void endScope(int frameSize) throws SAXException {
try {
for( ; frameSize>0; frameSize--, scopeTop-- )
scopes[scopeTop].finish();
for( ; frameSize>0; frameSize--, scopeTop-- ) {
Scope scope = scopes[scopeTop];
if (scope != null)
scope.finish();
}
} catch (AccessorException e) {
handleError(e);

Expand All @@ -1058,7 +1056,13 @@ public void endScope(int frameSize) throws SAXException {
* always a valid {@link Scope} object.
*/
public Scope getScope(int offset) {
return scopes[scopeTop-offset];
int position = scopeTop-offset;
Scope scope = scopes[position];
if (scope == null) {
scope = new Scope( this );
scopes[position] = scope;
}
return scope;
}

//
Expand Down

0 comments on commit 0f9b768

Please sign in to comment.