[svn:parrot] r49318 - in trunk/src: . pmc

plobsing at svn.parrot.org plobsing at svn.parrot.org
Sat Sep 25 04:12:27 UTC 2010


Author: plobsing
Date: Sat Sep 25 04:12:26 2010
New Revision: 49318
URL: https://trac.parrot.org/parrot/changeset/49318

Log:
eliminate special case for keys withing pbc
reduces rakudo startup by 0.1% and perl6.pbc size by 0.3%

Modified:
   trunk/src/packfile.c
   trunk/src/packout.c
   trunk/src/pmc/key.pmc

Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c	Sat Sep 25 02:28:14 2010	(r49317)
+++ trunk/src/packfile.c	Sat Sep 25 04:12:26 2010	(r49318)
@@ -3548,86 +3548,21 @@
     ASSERT_ARGS(PackFile_Constant_unpack_pmc)
     PackFile * const pf         = constt->base.pf;
     STRING          *_sub       = CONST_STRING(interp, "Sub");
-    const opcode_t   const_type = PF_fetch_opcode(pf, cursor);
+    PMC             *pmc;
+    /* thawing the PMC needs the real packfile in place */
+    PackFile_ByteCode * const cs_save = interp->code;
+    interp->code                      = pf->cur_cs;
+    pmc                               = Parrot_thaw_pbc(interp, constt, cursor);
+
+    /* finally place the sub into some namespace stash
+     * XXX place this code in Sub.thaw ?  */
+    if (VTABLE_isa(interp, pmc, _sub))
+        Parrot_ns_store_sub(interp, pmc);
 
-    switch (const_type) {
-      case PFC_KEY:
-        {
-            PMC    *head       = NULL;
-            PMC    *tail       = NULL;
-            INTVAL  components = (INTVAL)PF_fetch_opcode(pf, cursor);
-
-            while (components-- > 0) {
-                opcode_t       type       = PF_fetch_opcode(pf, cursor);
-                opcode_t        op;
-
-                if (tail) {
-                    SETATTR_Key_next_key(interp, tail, Parrot_pmc_new_constant(interp,
-                                                        enum_class_Key));
-                    GETATTR_Key_next_key(interp, tail, tail);
-                }
-                else
-                    head = tail = Parrot_pmc_new_constant(interp, enum_class_Key);
-
-                op = PF_fetch_opcode(pf, cursor);
-
-                switch (type) {
-                  case PARROT_ARG_IC:
-                    key_set_integer(interp, tail, op);
-                    break;
-                  case PARROT_ARG_NC:
-                    key_set_number(interp, tail, constt->num.constants[op]);
-                    break;
-                  case PARROT_ARG_SC:
-                    key_set_string(interp, tail, constt->str.constants[op]);
-                    break;
-                  case PARROT_ARG_I:
-                    key_set_register(interp, tail, op, KEY_integer_FLAG);
-                    break;
-                  case PARROT_ARG_N:
-                    key_set_register(interp, tail, op, KEY_number_FLAG);
-                    break;
-                  case PARROT_ARG_S:
-                    key_set_register(interp, tail, op, KEY_string_FLAG);
-                    break;
-                  case PARROT_ARG_P:
-                    key_set_register(interp, tail, op, KEY_pmc_FLAG);
-                    break;
-                  default:
-                    *cursor = NULL;
-                    return PMCNULL;
-                }
-            }
-
-            return head;
-        }
-
-      case PFC_PMC:
-        {
-            PMC             *pmc;
-            /* thawing the PMC needs the real packfile in place */
-            PackFile_ByteCode * const cs_save = interp->code;
-            interp->code                      = pf->cur_cs;
-            pmc                               = Parrot_thaw_pbc(interp, constt, cursor);
-
-            /* finally place the sub into some namespace stash
-             * XXX place this code in Sub.thaw ?  */
-            if (VTABLE_isa(interp, pmc, _sub))
-                Parrot_ns_store_sub(interp, pmc);
-
-            /* restore code */
-            interp->code = cs_save;
+    /* restore code */
+    interp->code = cs_save;
 
-            return pmc;
-        }
-
-      default:
-        Parrot_io_eprintf(NULL,
-                    "Constant_unpack: Unrecognized type '%c' during unpack!\n",
-                    (char)const_type);
-        *cursor = NULL;
-        return PMCNULL;
-    }
+    return pmc;
 }
 
 

Modified: trunk/src/packout.c
==============================================================================
--- trunk/src/packout.c	Sat Sep 25 02:28:14 2010	(r49317)
+++ trunk/src/packout.c	Sat Sep 25 04:12:26 2010	(r49318)
@@ -191,17 +191,7 @@
 
     for (i = 0; i < self->pmc.const_count; i++) {
         PMC *c = self->pmc.constants[i];
-        size += 1;
-        if (c->vtable->base_type == enum_class_Key) {
-            size += 1;
-            while (c) {
-                size += 2;
-                GETATTR_Key_next_key(interp, c, c);
-            }
-        }
-        else {
-            size += PF_size_strlen(Parrot_freeze_pbc_size(interp, c, self)) - 1;
-        }
+        size += PF_size_strlen(Parrot_freeze_pbc_size(interp, c, self)) - 1;
     }
 
     return size;
@@ -247,14 +237,7 @@
 
     for (i = 0; i < self->pmc.const_count; i++) {
         PMC *c = self->pmc.constants[i];
-        if (c->vtable->base_type == enum_class_Key) {
-            *cursor++ = PFC_KEY;
-             cursor   = PackFile_Constant_pack_key(interp, c, self, cursor);
-        }
-        else {
-            *cursor++ = PFC_PMC;
-             cursor   = Parrot_freeze_pbc(interp, c, self, cursor);
-        }
+        cursor   = Parrot_freeze_pbc(interp, c, self, cursor);
     }
 
     return cursor;

Modified: trunk/src/pmc/key.pmc
==============================================================================
--- trunk/src/pmc/key.pmc	Sat Sep 25 02:28:14 2010	(r49317)
+++ trunk/src/pmc/key.pmc	Sat Sep 25 04:12:26 2010	(r49318)
@@ -284,10 +284,6 @@
 
 /*
 
-=item C<void visit(PMC *info)>
-
-This is used by freeze/thaw to visit the contents of the Key.
-
 =item C<void freeze(PMC *info)>
 
 Archives the Key.
@@ -304,67 +300,97 @@
 
 */
 
-    VTABLE void visit(PMC *info) {
-        /* Sometimes visit gets an uninitialized Key.  Initialize it. */
-        if (!PMC_data(SELF))
-            SELF.init();
+    void freeze(PMC *info) {
+        int size;
+        PMC *k;
 
-        VISIT_PMC_ATTR(INTERP, info, SELF, Key, next_key);
-    }
+        for (size = 0, k = SELF; k; size++)
+            GET_ATTR_next_key(interp, k, k);
+        VTABLE_push_integer(INTERP, info, size);
+
+        for (k = SELF; k;) {
+            const INTVAL flags  = (PObj_get_FLAGS(k) & KEY_type_FLAGS);
+            VTABLE_push_integer(INTERP, info, flags);
+
+            switch (flags) {
+              case KEY_integer_FLAG | KEY_register_FLAG:
+              case KEY_number_FLAG  | KEY_register_FLAG:
+              case KEY_string_FLAG  | KEY_register_FLAG:
+              case KEY_integer_FLAG:
+                {
+                    INTVAL i;
+                    GET_ATTR_int_key(INTERP, k, i);
+                    VTABLE_push_integer(INTERP, info, i);
+                }
+                break;
 
-    void freeze(PMC *info) {
-        /* write flags */
-        const INTVAL flags  = (PObj_get_FLAGS(SELF) & KEY_type_FLAGS);
+              case KEY_number_FLAG:
+                {
+                    FLOATVAL f;
+                    GET_ATTR_num_key(INTERP, k, f);
+                    VTABLE_push_float(INTERP, info, f);
+                }
+                break;
+
+              case KEY_string_FLAG:
+                {
+                    STRING *s;
+                    GET_ATTR_str_key(INTERP, k, s);
+                    VTABLE_push_string(INTERP, info, s);
+                }
+                break;
+
+              default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_KEY_NOT_FOUND,
+                        "Unsupported key type in Key.freeze");
+                break;
+            }
 
-        /* write the contents of a register - else thaw can't restore
-         * the register state */
-        VTABLE_push_integer(INTERP, info, flags & ~KEY_register_FLAG);
-
-        /* and contents of this key component */
-        switch (flags) {
-          case KEY_integer_FLAG:
-          case KEY_integer_FLAG | KEY_register_FLAG:
-            VTABLE_push_integer(INTERP, info, key_integer(INTERP, SELF));
-            break;
-          case KEY_number_FLAG:
-          case KEY_number_FLAG | KEY_register_FLAG:
-            VTABLE_push_float(INTERP, info, key_number(INTERP, SELF));
-            break;
-          case KEY_string_FLAG:
-          case KEY_string_FLAG | KEY_register_FLAG:
-            VTABLE_push_string(INTERP, info, key_string(INTERP, SELF));
-            break;
-          default:
-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_KEY_NOT_FOUND,
-                    "Unsupported key type in Key.freeze");
-            break;
+            GET_ATTR_next_key(interp, k, k);
         }
     }
 
     void thaw(PMC *info) {
-        const INTVAL flags  = VTABLE_shift_integer(INTERP, info) & KEY_type_FLAGS;
+        int  size;
+        PMC *k = SELF;
 
-        PObj_get_FLAGS(SELF) |= flags;
         PObj_custom_mark_SET(SELF);
 
-        if (!PMC_data(SELF))
-            SELF.init();
+        for (size = VTABLE_shift_integer(INTERP, info); size; size--) {
+            const INTVAL flags  = VTABLE_shift_integer(INTERP, info) & KEY_type_FLAGS;
 
-        /* get contents */
-        switch (flags) {
-          case KEY_integer_FLAG:
-            SET_ATTR_int_key(INTERP, SELF, VTABLE_shift_integer(INTERP, info));
-            break;
-          case KEY_number_FLAG:
-            VTABLE_set_number_native(INTERP, SELF, VTABLE_shift_float(INTERP, info));
-            break;
-          case KEY_string_FLAG:
-            VTABLE_set_string_native(INTERP, SELF, VTABLE_shift_string(INTERP, info));
-            break;
-          default:
-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_KEY_NOT_FOUND,
-                    "Unsupported key type in Key.thaw");
-            break;
+            PObj_get_FLAGS(k) |= flags;
+
+            /* get contents */
+            switch (flags) {
+              case KEY_integer_FLAG | KEY_register_FLAG:
+              case KEY_number_FLAG  | KEY_register_FLAG:
+              case KEY_string_FLAG  | KEY_register_FLAG:
+              case KEY_integer_FLAG:
+                SET_ATTR_int_key(INTERP, k, VTABLE_shift_integer(INTERP, info));
+                break;
+
+              case KEY_number_FLAG:
+                VTABLE_set_number_native(INTERP, k, VTABLE_shift_float(INTERP, info));
+                break;
+
+              case KEY_string_FLAG:
+                VTABLE_set_string_native(INTERP, k, VTABLE_shift_string(INTERP, info));
+                break;
+
+              default:
+                Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_KEY_NOT_FOUND,
+                        "Unsupported key type in Key.thaw");
+                break;
+            }
+
+            if (size == 1) {
+                SET_ATTR_next_key(INTERP, k, NULL);
+            }
+            else {
+                SET_ATTR_next_key(INTERP, k, Parrot_pmc_new_constant(INTERP, enum_class_Key));
+                GET_ATTR_next_key(INTERP, k, k);
+            }
         }
     }
 


More information about the parrot-commits mailing list