зеркало из https://github.com/mozilla/pjs.git
Patch from Igor:
Replacing usage of ShallowNodeIterator to loop throw node children by explicit calls to Node.getFirstChild()/ Node.getNextSibling()) with comments when the node children list is modified while iterating through it. It avoids creation of ShallowNodeIterator objects and eliminates the need to have ShallowNodeIterator class.
This commit is contained in:
Родитель
afa2da21cc
Коммит
379b1c899f
|
@ -577,12 +577,13 @@ public class IRFactory {
|
|||
Node temp = createNewTemp(result);
|
||||
result = temp;
|
||||
|
||||
java.util.Enumeration children = ((Node) obj).getChildIterator();
|
||||
|
||||
Node elem = null;
|
||||
int i = 0;
|
||||
while (children.hasMoreElements()) {
|
||||
elem = (Node) children.nextElement();
|
||||
for (Node cursor = ((Node) obj).getFirstChild(); cursor != null;) {
|
||||
// Move cursor to cursor.next before elem.next can be
|
||||
// altered in new Node constructor
|
||||
elem = cursor;
|
||||
cursor = cursor.getNextSibling();
|
||||
if (elem.getType() == TokenStream.PRIMARY &&
|
||||
elem.getInt() == TokenStream.UNDEFINED)
|
||||
{
|
||||
|
@ -640,16 +641,16 @@ public class IRFactory {
|
|||
Node temp = createNewTemp(result);
|
||||
result = temp;
|
||||
|
||||
java.util.Enumeration children = ((Node) obj).getChildIterator();
|
||||
|
||||
while (children.hasMoreElements()) {
|
||||
Node elem = (Node)children.nextElement();
|
||||
|
||||
int op = (elem.getType() == TokenStream.NAME)
|
||||
for (Node cursor = ((Node) obj).getFirstChild(); cursor != null;) {
|
||||
Node n = cursor;
|
||||
cursor = cursor.getNextSibling();
|
||||
int op = (n.getType() == TokenStream.NAME)
|
||||
? TokenStream.SETPROP
|
||||
: TokenStream.SETELEM;
|
||||
Node addelem = new Node(op, createUseTemp(temp),
|
||||
elem, (Node)children.nextElement());
|
||||
// Move cursor before next.next can be altered in new Node
|
||||
Node next = cursor;
|
||||
cursor = cursor.getNextSibling();
|
||||
Node addelem = new Node(op, createUseTemp(temp), n, next);
|
||||
result = new Node(TokenStream.COMMA, result, addelem);
|
||||
}
|
||||
return new Node(TokenStream.COMMA, result, createUseTemp(temp));
|
||||
|
@ -693,7 +694,7 @@ public class IRFactory {
|
|||
result.addChildToBack(ifNotTarget);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
public Object createTernary(Object cond, Object ifTrue, Object ifFalse) {
|
||||
|
@ -728,7 +729,7 @@ public class IRFactory {
|
|||
}
|
||||
return new Node(nodeType, left, right);
|
||||
}
|
||||
return new Node(nodeType, childNode);
|
||||
return new Node(nodeType, childNode);
|
||||
}
|
||||
|
||||
public Object createUnary(int nodeType, int nodeOp, Object child) {
|
||||
|
@ -810,7 +811,7 @@ public class IRFactory {
|
|||
return createTernary(temp, createUseTemp(temp), right);
|
||||
*/
|
||||
}
|
||||
return new Node(nodeType, (Node)left, (Node)right);
|
||||
return new Node(nodeType, (Node)left, (Node)right);
|
||||
}
|
||||
|
||||
public Object createBinary(int nodeType, int nodeOp, Object left,
|
||||
|
|
|
@ -147,10 +147,6 @@ public class Node implements Cloneable {
|
|||
return n;
|
||||
}
|
||||
|
||||
public ShallowNodeIterator getChildIterator() {
|
||||
return new ShallowNodeIterator(first);
|
||||
}
|
||||
|
||||
public PreorderNodeIterator getPreorderIterator() {
|
||||
return new PreorderNodeIterator(this);
|
||||
}
|
||||
|
@ -484,17 +480,16 @@ public class Node implements Cloneable {
|
|||
}
|
||||
s.append(toString());
|
||||
s.append('\n');
|
||||
ShallowNodeIterator iterator = getChildIterator();
|
||||
if (iterator != null) {
|
||||
while (iterator.hasMoreElements()) {
|
||||
Node n = (Node) iterator.nextElement();
|
||||
if (n.getType() == TokenStream.FUNCTION) {
|
||||
Node p = (Node) n.getProp(Node.FUNCTION_PROP);
|
||||
if (p != null)
|
||||
n = p;
|
||||
}
|
||||
s.append(n.toStringTreeHelper(level+1));
|
||||
for (Node cursor = getFirstChild(); cursor != null;
|
||||
cursor = cursor.getNextSibling())
|
||||
{
|
||||
Node n = cursor;
|
||||
if (cursor.getType() == TokenStream.FUNCTION) {
|
||||
Node p = (Node) cursor.getProp(Node.FUNCTION_PROP);
|
||||
if (p != null)
|
||||
n = p;
|
||||
}
|
||||
s.append(n.toStringTreeHelper(level+1));
|
||||
}
|
||||
return s.toString();
|
||||
}
|
||||
|
|
|
@ -407,10 +407,12 @@ public class NodeTransformer {
|
|||
|
||||
case TokenStream.VAR:
|
||||
{
|
||||
ShallowNodeIterator i = node.getChildIterator();
|
||||
Node result = new Node(TokenStream.BLOCK);
|
||||
while (i.hasMoreElements()) {
|
||||
Node n = i.nextNode();
|
||||
for (Node cursor = node.getFirstChild(); cursor != null;) {
|
||||
// Move cursor to next before createAssignment get chance
|
||||
// to change n.next
|
||||
Node n = cursor;
|
||||
cursor = cursor.getNextSibling();
|
||||
if (!n.hasChildren())
|
||||
continue;
|
||||
Node init = n.getFirstChild();
|
||||
|
@ -519,11 +521,11 @@ public class NodeTransformer {
|
|||
}
|
||||
if (nodeType != TokenStream.VAR)
|
||||
continue;
|
||||
ShallowNodeIterator i = node.getChildIterator();
|
||||
while (i.hasMoreElements()) {
|
||||
Node n = i.nextNode();
|
||||
if (ht == null || ht.get(n.getString()) == null)
|
||||
vars.addLocal(n.getString());
|
||||
for (Node cursor = node.getFirstChild(); cursor != null;
|
||||
cursor = cursor.getNextSibling())
|
||||
{
|
||||
if (ht == null || ht.get(cursor.getString()) == null)
|
||||
vars.addLocal(cursor.getString());
|
||||
}
|
||||
}
|
||||
String name = tree.getString();
|
||||
|
@ -554,10 +556,10 @@ public class NodeTransformer {
|
|||
if (args.getType() == TokenStream.LP && vars.getParameterCount() == 0)
|
||||
{
|
||||
// Add parameters
|
||||
ShallowNodeIterator i = args.getChildIterator();
|
||||
while (i.hasMoreElements()) {
|
||||
Node n = i.nextNode();
|
||||
String arg = n.getString();
|
||||
for (Node cursor = args.getFirstChild(); cursor != null;
|
||||
cursor = cursor.getNextSibling())
|
||||
{
|
||||
String arg = cursor.getString();
|
||||
vars.addParameter(arg);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче