Skip to content

Instantly share code, notes, and snippets.

View methodmissing's full-sized avatar

Lourens Naudé methodmissing

View GitHub Profile
/* hash.c */
static int
rb_strhash_hash_cmp(VALUE a, VALUE b)
{
#ifdef RUBY18
VALUE args[2];
#endif
if (a == b) return 0;
if (FIXNUM_P(a) && FIXNUM_P(b)) return a != b;
if (a == Qundef || b == Qundef) return -1;
static int
strhash(register const char *string)
{
register int c;
register int val = 0;
while ((c = *string++) != '\0') {
val = val*997 + c;
}
return val + (val>>5);
}
struct RHash {
struct RBasic basic;
struct st_table *tbl;
int iter_lev;
VALUE ifnone;
};
static struct st_hash_type objhash = {
rb_any_cmp,
rb_any_hash,
};
static VALUE
hash_alloc(klass)
VALUE klass;
{
VALUE hash = hash_alloc0(klass);
static int
rb_any_hash(a)
VALUE a;
{
VALUE hval;
switch (TYPE(a)) {
case T_FIXNUM:
case T_SYMBOL:
return (int)a;
static int
rb_any_cmp(a, b)
VALUE a, b;
{
VALUE args[2];
if (a == b) return 0;
if (FIXNUM_P(a) && FIXNUM_P(b)) {
return a != b;
}
static VALUE
flo_to_s(flt)
VALUE flt;
{
char buf[32];
double value = RFLOAT(flt)->value;
char *p, *e;
if (isinf(value))
return rb_str_new2(value < 0 ? "-Infinity" : "Infinity");
diff --git a/activesupport/lib/active_support/core_ext/hash.rb b/activesupport/lib/active_support/core_ext/hash.rb
index 5014834..591363d 100644
--- a/activesupport/lib/active_support/core_ext/hash.rb
+++ b/activesupport/lib/active_support/core_ext/hash.rb
@@ -6,3 +6,5 @@ require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/hash/reverse_merge'
require 'active_support/core_ext/hash/slice'
+
+require 'hwia_rails'
methodmissing:hwia lourens$ rake bench
(in /Users/lourens/projects/hwia)
/opt/local/bin/ruby bench/bench.rb
Rehearsal ------------------------------------------------------------------------------
StrHash#[:sym] 0.000000 0.000000 0.000000 ( 0.002949)
HashWithIndifferentAccess#[:sym] 0.020000 0.000000 0.020000 ( 0.021825)
StrHash#['str'] 0.010000 0.000000 0.010000 ( 0.012166)
HashWithIndifferentAccess#['str] 0.000000 0.000000 0.000000 ( 0.003780)
StrHash#key?(:sym) 0.010000 0.000000 0.010000 ( 0.002945)
HashWithIndifferentAccess#key?(:sym) 0.010000 0.000000 0.010000 ( 0.013988)
methodmissing:activesupport lourens$ git diff
diff --git a/activesupport/lib/active_support/core_ext/hash.rb b/activesupport/lib/active_support/core_ext/hash.rb
index 5014834..591363d 100644
--- a/activesupport/lib/active_support/core_ext/hash.rb
+++ b/activesupport/lib/active_support/core_ext/hash.rb
@@ -6,3 +6,5 @@ require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/hash/reverse_merge'
require 'active_support/core_ext/hash/slice'
+