Author: mdiep
Date: Thu May 3 16:22:12 2007
New Revision: 18414
Modified:
trunk/lib/Parrot/Vtable.pm
trunk/src/objects.c
Log:
Sort the vtable functions list alphabetically and use a binary search when
looking functions up by name. This gets us part way to some of the speedup we
should see from the pdd15 implementation.
Time to run ../../parrot tcl.pbc t/cmd_append.t
Before: 10.3s
After: 9.3s
You may need to 'make clean'.
Modified: trunk/lib/Parrot/Vtable.pm
==============================================================================
--- trunk/lib/Parrot/Vtable.pm (original)
+++ trunk/lib/Parrot/Vtable.pm Thu May 3 16:22:12 2007
@@ -77,6 +77,7 @@
my $file = defined $_[0] ? shift() : 'vtable.tbl';
my $vtable = [];
+ my $mmd = [];
my $fh = FileHandle->new( $file, O_RDONLY )
or die "Can't open $file for reading: $!\n";
my $section = 'MAIN';
@@ -99,16 +100,24 @@
(?:\s+(MMD_\w+))?\s*($attrs_re)$/x
)
{
- my $mmd = defined $4 ? $4 : -1;
+ my $mmdop = defined $4 ? $4 : -1;
- push @{$vtable}, [ $1, $2, $3, $section, $mmd, parse_attrs( $5,
$default_attrs ) ];
+ my $entry = [ $1, $2, $3, $section, $mmdop, parse_attrs( $5,
$default_attrs ) ];
+ if (defined $4) {
+ push @{$mmd}, $entry;
+ }
+ else {
+ push @{$vtable}, $entry;
+ }
}
else {
die "Syntax error at $file line " . $fh->input_line_number() .
"\n";
}
}
-
- return $vtable;
+
+ # We probably should sort on insert, but this is easier for now. And it's
+ # compile time, so it's not all that important.
+ return [EMAIL PROTECTED], sort { $a->[1] cmp $b->[1] } @$vtable];
}
=item C<vtbl_defs($vtable)>
@@ -252,8 +261,10 @@
/* Vtable Functions */
EOM
+ my $num_vtable_funcs = 0;
for my $entry ( @{$vtable} ) {
next if ( $entry->[4] =~ /MMD_/ );
+ $num_vtable_funcs++;
$macros .= <<"EOM";
\"__$entry->[1]\",
EOM
@@ -262,6 +273,8 @@
NULL
};
+#define NUM_VTABLE_FUNCTIONS $num_vtable_funcs
+
#endif /* PARROT_IN_OBJECTS_C */
/* Need this for add, subtract, multiply, divide, mod, cmod, bitwise
Modified: trunk/src/objects.c
==============================================================================
--- trunk/src/objects.c (original)
+++ trunk/src/objects.c Thu May 3 16:22:12 2007
@@ -40,20 +40,32 @@
INTVAL
Parrot_get_vtable_index(Interp *interp, STRING *name)
{
- const char *meth_c;
- char *name_c = string_to_cstring(interp, name);
- INTVAL i;
-
- for (i = 0; (meth_c = Parrot_vtable_slot_names[i]); ++i) {
- /* some of the first vtable slots don't have names */
- if (!*meth_c)
- continue;
+ char *name_c = string_to_cstring(interp, name);
+
+ INTVAL low = 0;
+ INTVAL high = NUM_VTABLE_FUNCTIONS - 1;
+
+ /* some of the first "slots" don't have names. skip 'em. */
+ while (!Parrot_vtable_slot_names[low]) {
+ low++;
+ high++;
+ }
+ while (low <= high) {
+ INTVAL i = (low + high) / 2;
+
+ const char *meth_c = Parrot_vtable_slot_names[i];
/* XXX slot_names still have __ in front */
- if (strcmp(name_c, meth_c + 2) == 0) {
+ int cmp = strcmp(name_c, meth_c + 2);
+
+ if (!cmp) {
string_cstring_free(name_c);
return i;
}
+ else if (cmp > 0)
+ low = i + 1;
+ else
+ high = i - 1;
}
string_cstring_free(name_c);