[svn:parrot] r48415 - in trunk: compilers/opsc/src/Ops/Trans src/ops

chromatic at svn.parrot.org chromatic at svn.parrot.org
Wed Aug 11 08:08:45 UTC 2010


Author: chromatic
Date: Wed Aug 11 08:08:44 2010
New Revision: 48415
URL: https://trac.parrot.org/parrot/changeset/48415

Log:
[opsc] Made hop_init() walk the op list only once.

This speeds up Parrot startup by another ~1%.

Modified:
   trunk/compilers/opsc/src/Ops/Trans/C.pm
   trunk/src/ops/core_ops.c

Modified: trunk/compilers/opsc/src/Ops/Trans/C.pm
==============================================================================
--- trunk/compilers/opsc/src/Ops/Trans/C.pm	Wed Aug 11 07:02:14 2010	(r48414)
+++ trunk/compilers/opsc/src/Ops/Trans/C.pm	Wed Aug 11 08:08:44 2010	(r48415)
@@ -286,7 +286,7 @@
 
 static void hop_init(PARROT_INTERP);
 static size_t hash_str(const char *str);
-static void store_op(PARROT_INTERP, op_info_t *info, HOP *p, int full);
+static void store_op(PARROT_INTERP, op_info_t *info, HOP *p, const char *name);
 
 /* XXX on changing interpreters, this should be called,
    through a hook */
@@ -318,31 +318,35 @@
     return key;
 }
 
-static void store_op(PARROT_INTERP, op_info_t *info, HOP *p, int full)
+
+static void store_op(PARROT_INTERP, op_info_t *info, HOP *p, const char *name)
 {
-    const size_t hidx =
-        hash_str(full ? info->full_name : info->name) % OP_HASH_SIZE;
+    const size_t hidx = hash_str(name) % OP_HASH_SIZE;
 
-    p->info   = info;
-    p->next   = hop[hidx];
-    hop[hidx] = p;
+    p->info           = info;
+    p->next           = hop[hidx];
+    hop[hidx]         = p;
 }
 
-static int get_op(PARROT_INTERP, const char * name, int full)
+static int get_op(PARROT_INTERP, const char *name, int full)
 {
-    const HOP * p;
+    const HOP   *p;
     const size_t hidx = hash_str(name) % OP_HASH_SIZE;
+
     if (!hop) {
         hop = mem_gc_allocate_n_zeroed_typed(interp, OP_HASH_SIZE,HOP *);
         hop_init(interp);
     }
+
     for (p = hop[hidx]; p; p = p->next) {
-        if(STREQ(name, full ? p->info->full_name : p->info->name))
+        if (STREQ(name, full ? p->info->full_name : p->info->name))
             return p->info - [[BS]]op_lib.op_info_table;
     }
+
     return -1;
 }
 
+
 static void hop_init(PARROT_INTERP)
 {
     op_info_t * const info = [[BS]]op_lib.op_info_table;
@@ -355,13 +359,13 @@
     size_t i;
 
     /* store full names */
-    for (i = 0; i < [[BS]]op_lib.op_count; i++)
-        store_op(interp, info + i, hops++, 1);
+    for (i = 0; i < [[BS]]op_lib.op_count; i++) {
+        store_op(interp, info + i, hops++, info[i].full_name);
 
-    /* plus one short name */
-    for (i = 0; i < [[BS]]op_lib.op_count; i++)
-        if (get_op(interp, info[i].name, 0) == -1)
-            store_op(interp, info + i, hops++, 0);
+        /* plus one short name */
+        if (i && info[i - 1].name != info[i].name)
+            store_op(interp, info + i, hops++, info[i].name);
+    }
 }
 
 static void hop_deinit(PARROT_INTERP)

Modified: trunk/src/ops/core_ops.c
==============================================================================
--- trunk/src/ops/core_ops.c	Wed Aug 11 07:02:14 2010	(r48414)
+++ trunk/src/ops/core_ops.c	Wed Aug 11 08:08:44 2010	(r48415)
@@ -26138,7 +26138,7 @@
 
 static void hop_init(PARROT_INTERP);
 static size_t hash_str(const char *str);
-static void store_op(PARROT_INTERP, op_info_t *info, HOP *p, int full);
+static void store_op(PARROT_INTERP, op_info_t *info, HOP *p, const char *name);
 
 /* XXX on changing interpreters, this should be called,
    through a hook */
@@ -26170,31 +26170,35 @@
     return key;
 }
 
-static void store_op(PARROT_INTERP, op_info_t *info, HOP *p, int full)
+
+static void store_op(PARROT_INTERP, op_info_t *info, HOP *p, const char *name)
 {
-    const size_t hidx =
-        hash_str(full ? info->full_name : info->name) % OP_HASH_SIZE;
+    const size_t hidx = hash_str(name) % OP_HASH_SIZE;
 
-    p->info   = info;
-    p->next   = hop[hidx];
-    hop[hidx] = p;
+    p->info           = info;
+    p->next           = hop[hidx];
+    hop[hidx]         = p;
 }
 
-static int get_op(PARROT_INTERP, const char * name, int full)
+static int get_op(PARROT_INTERP, const char *name, int full)
 {
-    const HOP * p;
+    const HOP   *p;
     const size_t hidx = hash_str(name) % OP_HASH_SIZE;
+
     if (!hop) {
         hop = mem_gc_allocate_n_zeroed_typed(interp, OP_HASH_SIZE,HOP *);
         hop_init(interp);
     }
+
     for (p = hop[hidx]; p; p = p->next) {
-        if(STREQ(name, full ? p->info->full_name : p->info->name))
+        if (STREQ(name, full ? p->info->full_name : p->info->name))
             return p->info - core_op_lib.op_info_table;
     }
+
     return -1;
 }
 
+
 static void hop_init(PARROT_INTERP)
 {
     op_info_t * const info = core_op_lib.op_info_table;
@@ -26207,13 +26211,13 @@
     size_t i;
 
     /* store full names */
-    for (i = 0; i < core_op_lib.op_count; i++)
-        store_op(interp, info + i, hops++, 1);
+    for (i = 0; i < core_op_lib.op_count; i++) {
+        store_op(interp, info + i, hops++, info[i].full_name);
 
-    /* plus one short name */
-    for (i = 0; i < core_op_lib.op_count; i++)
-        if (get_op(interp, info[i].name, 0) == -1)
-            store_op(interp, info + i, hops++, 0);
+        /* plus one short name */
+        if (i && info[i - 1].name != info[i].name)
+            store_op(interp, info + i, hops++, info[i].name);
+    }
 }
 
 static void hop_deinit(PARROT_INTERP)


More information about the parrot-commits mailing list