ext/template/google_hash.cpp.erb in google_hash-0.8.9 vs ext/template/google_hash.cpp.erb in google_hash-0.9.0
- old
+ new
@@ -94,14 +94,26 @@
// slows down string 21/22
// ltodo
if(s1 == s2) {
return true;
}
-
- // this line from object.c's rb_eql
- // lookup 0.278 -> 0.26
+ // the weird part here is that eqrb is used during iteration
+ // to iterate over the entire "hash space" and see which objects are
+ // "live" and which are "dead" in its iterator (as well as being used at insertion time)
+ // during gc, it was calling in to a real ruby "==" for the "live" objects
+ // which, if they used any type of allocation -> segfault
+ // since we're only dealing with ruby VALUE's here, I think we're guaranteed that they can't be NULL
+ <% if type == 'dense' %>
+ if (s2 == <%= unreachable_key %> || s2 == <%= deleted_key %> || s1 == <%= unreachable_key %> || s1 == <%= deleted_key %>) {
+ <% elsif type == 'sparse' %>
+ if (s2 == <%= unreachable_key %> || s1 == <%= unreachable_key %>) {
+ <% end %>
+ return s1 == s2; // comparison with these freako keys is straight forward :)
+ }
+ // this line (cacheing id_eql) from object.c's rb_eql
+ // lookup 0.278 -> 0.26
return RTEST(rb_funcall(s1, id_eql, 1, s2));
}
};
#ifndef RBIGNUM_DIGITS
@@ -197,11 +209,11 @@
cbs->hash_map = new <%= type %>_hash_map< <%= key_type %>, <%= value_type %> <%= extra_hash_params %> >();
<% if type == 'dense' %>
// needs both empty key and deleted keys [and different] for deletes...
cbs->hash_map->set_empty_key(<%= unreachable_key %>);
- // in th eory could also call set_deleted_key "anytime" ...
- cbs->hash_map->set_deleted_key((<%= unreachable_key %>)-1); // hope this is also typically unreachable from ruby land [?]
+ // in theory could also call set_deleted_key "anytime" ... but why not do it now
+ cbs->hash_map->set_deleted_key(<%= deleted_key %>);
<% elsif type == 'sparse' %>
cbs->hash_map->set_deleted_key(<%= unreachable_key %>);
<% end %>
return current_instance;