Skip to content

Commit d194050

Browse files
committed
simplify id_to_fptrs array for faster deserialization
1 parent a2dcc94 commit d194050

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/dump.c

+26-27
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,25 @@ static arraylist_t methtable_list;
4040
static htable_t fptr_to_id;
4141
// array of definitions for the predefined function pointers
4242
// (reverse of fptr_to_id)
43-
static htable_t id_to_fptr;
43+
static jl_fptr_t id_to_fptrs[] = {
44+
NULL, NULL,
45+
jl_f_throw, jl_f_is,
46+
jl_f_no_function, jl_f_typeof,
47+
jl_f_subtype, jl_f_isa,
48+
jl_f_typeassert, jl_f_apply,
49+
jl_f_top_eval, jl_f_isdefined,
50+
jl_f_tuple, jl_f_tupleref,
51+
jl_f_tuplelen, jl_f_get_field,
52+
jl_f_set_field, jl_f_field_type,
53+
jl_f_arraylen, jl_f_arrayref,
54+
jl_f_arrayset, jl_f_arraysize,
55+
jl_f_instantiate_type, jl_f_kwcall,
56+
jl_trampoline, jl_f_union,
57+
jl_f_methodexists, jl_f_applicable,
58+
jl_f_invoke, jl_apply_generic,
59+
jl_unprotect_stack,
60+
jl_f_yieldto, jl_f_sizeof, jl_f_new_expr,
61+
NULL };
4462

4563
// pointers to non-AST-ish objects in a compressed tree
4664
static jl_array_t *tree_literal_values=NULL; // (only used in MODE_AST)
@@ -789,12 +807,12 @@ void jl_serialize_lambdas_from_mod(ios_t *s, jl_module_t *m)
789807
static jl_fptr_t jl_deserialize_fptr(ios_t *s)
790808
{
791809
int fptr = read_uint16(s);
792-
if (fptr == 0)
810+
if (fptr < 2)
793811
return NULL;
794-
void **pbp = ptrhash_bp(&id_to_fptr, (void*)(ptrint_t)fptr);
795-
if (*pbp == HT_NOTFOUND)
812+
813+
if (fptr >= sizeof(id_to_fptrs)/sizeof(*id_to_fptrs))
796814
jl_error("unknown function pointer ID");
797-
return *(jl_fptr_t*)pbp;
815+
return id_to_fptrs[fptr];
798816
}
799817

800818
static jl_value_t *jl_deserialize_datatype(ios_t *s, int pos, jl_value_t **loc)
@@ -1669,8 +1687,7 @@ jl_module_t *jl_restore_new_module(char *fname)
16691687
void jl_init_serializer(void)
16701688
{
16711689
htable_new(&ser_tag, 0);
1672-
htable_new(&fptr_to_id, 0);
1673-
htable_new(&id_to_fptr, 0);
1690+
htable_new(&fptr_to_id, sizeof(id_to_fptrs)/sizeof(*id_to_fptrs));
16741691
htable_new(&backref_table, 50000);
16751692

16761693
void *tags[] = { jl_symbol_type, jl_datatype_type,
@@ -1794,27 +1811,9 @@ void jl_init_serializer(void)
17941811
assert(i <= Null_tag);
17951812
VALUE_TAGS = (ptrint_t)ptrhash_get(&ser_tag, jl_null);
17961813

1797-
jl_fptr_t fptrs[] = { jl_f_throw, jl_f_is,
1798-
jl_f_no_function, jl_f_typeof,
1799-
jl_f_subtype, jl_f_isa,
1800-
jl_f_typeassert, jl_f_apply,
1801-
jl_f_top_eval, jl_f_isdefined,
1802-
jl_f_tuple, jl_f_tupleref,
1803-
jl_f_tuplelen, jl_f_get_field,
1804-
jl_f_set_field, jl_f_field_type,
1805-
jl_f_arraylen, jl_f_arrayref,
1806-
jl_f_arrayset, jl_f_arraysize,
1807-
jl_f_instantiate_type, jl_f_kwcall,
1808-
jl_trampoline, jl_f_union,
1809-
jl_f_methodexists, jl_f_applicable,
1810-
jl_f_invoke, jl_apply_generic,
1811-
jl_unprotect_stack,
1812-
jl_f_yieldto, jl_f_sizeof, jl_f_new_expr,
1813-
NULL };
18141814
i=2;
1815-
while (fptrs[i-2] != NULL) {
1816-
ptrhash_put(&fptr_to_id, (void*)fptrs[i-2], (void*)i);
1817-
ptrhash_put(&id_to_fptr, (void*)i, (void*)fptrs[i-2]);
1815+
while (id_to_fptrs[i] != NULL) {
1816+
ptrhash_put(&fptr_to_id, (void*)id_to_fptrs[i], (void*)i);
18181817
i += 1;
18191818
}
18201819
}

0 commit comments

Comments
 (0)