From 3b2cd42b0addb578812fe70460ae4dba7969d244 Mon Sep 17 00:00:00 2001 From: Arne Goedeke <el@laramies.com> Date: Sun, 4 Nov 2012 18:59:56 +0100 Subject: [PATCH] mapping: remove overoptimization when looking up objects --- src/mapping.c | 8 ++++++-- src/testsuite.in | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/mapping.c b/src/mapping.c index 54675d3732..170446cf59 100644 --- a/src/mapping.c +++ b/src/mapping.c @@ -117,6 +117,10 @@ void mapping_free_keypair(struct mapping_data *md, struct keypair *k) FREE_KEYPAIR(md, k); } +static INLINE int check_type_contains(TYPE_FIELD types, const struct svalue * s) { + return (TYPEOF(*s) == PIKE_T_OBJECT || types & (BIT_OBJECT|(1 << TYPEOF(*s)))); +} + #ifdef PIKE_DEBUG /** This function checks that the type field isn't lacking any bits. @@ -549,7 +553,7 @@ struct mapping_data *copy_mapping_data(struct mapping_data *md) { \ h=h2 & (md->hashsize - 1); \ DO_IF_DEBUG( if(d_flag > 1) check_mapping_type_fields(m); ) \ - if(md->ind_types & ((1 << TYPEOF(*key)) | BIT_OBJECT)) \ + if(check_type_contains(md->ind_types, key)) \ { \ for(prev= md->hash + h;(k=*prev);prev=&k->next) \ { \ @@ -572,7 +576,7 @@ struct mapping_data *copy_mapping_data(struct mapping_data *md) { \ h=h2 & (md->hashsize-1); \ DO_IF_DEBUG( if(d_flag > 1) check_mapping_type_fields(m); ) \ - if(md->ind_types & ((1 << TYPEOF(*key)) | BIT_OBJECT)) \ + if(check_type_contains(md->ind_types, key)) \ { \ k2=omd->hash[h2 & (omd->hashsize - 1)]; \ prev= md->hash + h; \ diff --git a/src/testsuite.in b/src/testsuite.in index b4f6c85d29..6a686a4e5c 100644 --- a/src/testsuite.in +++ b/src/testsuite.in @@ -5779,6 +5779,24 @@ void create() ]]) +test_any([[ + mapping m = ([ "foo" : 1 ]); + class A { + int __hash() { return hash_value("foo"); } + int `==(mixed o) { return o == "foo"; } + }; + return m[A()]; +]], 1) + +test_any([[ + mapping m = ([ "foo" : 1 ]); + class A { + int __hash() { return hash_value("foo"); } + int `==(mixed o) { return o == "foo"; } + }; + return sizeof(m - ([ A() : 1 ])); +]], 0) + test_equal([[ `+( ([1:2]) )]],[[ ([1:2]) ]]) test_false( `+( ([1:2]) ) == ([1:2]) ) test_equal([[ `+( ([1:2]), ([1:2]) )]],[[ ([1:2]) ]]) -- GitLab