[svn:parrot] r36443 - trunk/lib/Parrot/Pmc2c

NotFound at svn.parrot.org NotFound at svn.parrot.org
Sun Feb 8 13:12:49 UTC 2009


Author: NotFound
Date: Sun Feb  8 13:12:48 2009
New Revision: 36443
URL: https://trac.parrot.org/parrot/changeset/36443

Log:
[cage] avoid regex duplications in Parrot::Pmc2c::Attribute

Modified:
   trunk/lib/Parrot/Pmc2c/Attribute.pm

Modified: trunk/lib/Parrot/Pmc2c/Attribute.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/Attribute.pm	Sun Feb  8 12:41:51 2009	(r36442)
+++ trunk/lib/Parrot/Pmc2c/Attribute.pm	Sun Feb  8 13:12:48 2009	(r36443)
@@ -99,6 +99,11 @@
     my $pmcname        = $pmc->{name};
     my $attrtype       = $self->{type};
     my $attrname       = $self->{name};
+
+    # Store regexes used to check some types to avoid repetitions
+    my $isptrtostring = qr/STRING\s*\*$/;
+    my $isptrtopmc    = qr/PMC\s*\*$/;
+
     my $decl           = <<"EOA";
 
 /* Generated macro accessors for '$attrname' attribute of $pmcname PMC. */
@@ -121,14 +126,14 @@
             (dest) = VTABLE_get_number(interp, attr_value); \\
 EOA
     }
-    elsif ($attrtype =~ /STRING\s*\*$/) {
+    elsif ($attrtype =~ $isptrtostring) {
         $decl .= <<"EOA";
             PMC *attr_value = VTABLE_get_attr_str(interp, \\
                               pmc, Parrot_str_new_constant(interp, "$attrname")); \\
             (dest) = VTABLE_get_string(interp, attr_value); \\
 EOA
     }
-    elsif ($attrtype =~ /PMC\s*\*$/) {
+    elsif ($attrtype =~ $isptrtopmc) {
         $decl .= <<"EOA";
             (dest) = VTABLE_get_attr_str(interp, \\
                               pmc, Parrot_str_new_constant(interp, "$attrname")); \\
@@ -170,7 +175,7 @@
                               Parrot_str_new_constant(interp, "$attrname"), attr_value); \\
 EOA
     }
-    elsif ($attrtype =~ /STRING\s*\*$/) {
+    elsif ($attrtype =~ $isptrtostring) {
         $decl .= <<"EOA";
             PMC *attr_value = pmc_new(interp, enum_class_String); \\
             VTABLE_set_string_native(interp, attr_value, value); \\
@@ -178,7 +183,7 @@
                               Parrot_str_new_constant(interp, "$attrname"), attr_value); \\
 EOA
     }
-    elsif ($attrtype =~ /PMC\s*\*$/) {
+    elsif ($attrtype =~ $isptrtopmc) {
         $decl .= <<"EOA";
             VTABLE_set_attr_str(interp, pmc, \\
                               Parrot_str_new_constant(interp, "$attrname"), value); \\


More information about the parrot-commits mailing list