develooper Front page | perl.perl5.porters | Postings from July 2001

[PATCH op.c] Constant folding index()/rindex()

From:
Simon Cozens
Date:
July 4, 2001 12:27
Subject:
[PATCH op.c] Constant folding index()/rindex()
Message ID:
20010704202750.A3801@deep-dark-truthful-mirror
Experimental. Folds index(CONSTANT, CONSTANT[, CONSTANT]) at compile time.

--- opcode.pl~	Wed Jul  4 20:26:38 2001
+++ opcode.pl	Wed Jul  4 20:26:47 2001
@@ -560,8 +560,8 @@
 substr		substr			ck_substr	st@	S S S? S?
 vec		vec			ck_fun		ist@	S S S
 
-index		index			ck_index	isT@	S S S?
-rindex		rindex			ck_index	isT@	S S S?
+index		index			ck_index	isfT@	S S S?
+rindex		rindex			ck_index	isfT@	S S S?
 
 sprintf		sprintf			ck_fun		mfst@	S L
 formline	formline		ck_fun		ms@	S L
--- op.c~	Wed Jul  4 10:43:48 2001
+++ op.c	Wed Jul  4 14:54:39 2001
@@ -5948,10 +5948,18 @@
 {
     if (o->op_flags & OPf_KIDS) {
 	OP *kid = cLISTOPo->op_first->op_sibling;	/* get past pushmark */
+        OP *big = kid;
 	if (kid)
 	    kid = kid->op_sibling;			/* get past "big" */
-	if (kid && kid->op_type == OP_CONST)
-	    fbm_compile(((SVOP*)kid)->op_sv, 0);
+	if (kid && kid->op_type == OP_CONST) {
+            fbm_compile(((SVOP*)kid)->op_sv, 0);
+            if (big && big->op_type == OP_CONST && 
+                (!kid->op_sibling || kid->op_sibling->op_type == OP_CONST)) {
+                if (kid->op_sibling)
+                    o->op_private = 3;
+                return fold_constants(o);
+            }
+        }
     }
     return ck_fun(o);
 }

-- 
linux-2.3.99-pre9.tar: limbo program
    - plan9 has a bad day



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About