]> git.saurik.com Git - cycript.git/commitdiff
Avoid deep replace when lifting for-in assignments.
authorJay Freeman (saurik) <saurik@saurik.com>
Tue, 5 Jun 2012 10:21:23 +0000 (03:21 -0700)
committerJay Freeman (saurik) <saurik@saurik.com>
Tue, 5 Jun 2012 10:21:23 +0000 (03:21 -0700)
Replace.cpp

index 2caa728e32e4ed39af2d64a12b763357dcb7ddf4..9a2717147dc4bc2d6a99659d76ec46f30fa083b6 100644 (file)
@@ -198,7 +198,10 @@ CYStatement *CYContinue::Replace(CYContext &context) {
 CYAssignment *CYDeclaration::Assignment(CYContext &context) {
     if (initialiser_ == NULL)
         return NULL;
-    return $ CYAssign(Variable(context), initialiser_);
+
+    CYAssignment *value($ CYAssign(Variable(context), initialiser_));
+    initialiser_ = NULL;
+    return value;
 }
 
 CYVariable *CYDeclaration::Variable(CYContext &context) {
@@ -319,18 +322,15 @@ CYCompound *CYForDeclarations::Replace(CYContext &context) {
 
 // XXX: this still feels highly suboptimal
 CYStatement *CYForIn::Replace(CYContext &context) {
-    CYForInInitialiser *initialiser(initialiser_);
-
-    context.Replace(initialiser_);
-    context.Replace(set_);
-    context.Replace(code_);
-
-    if (CYAssignment *assignment = initialiser->Assignment(context))
+    if (CYAssignment *assignment = initialiser_->Assignment(context))
         return $ CYBlock($$->*
             $E(assignment)->*
             this
         );
 
+    context.Replace(initialiser_);
+    context.Replace(set_);
+    context.Replace(code_);
     return this;
 }