Created
August 19, 2009 08:10
-
-
Save methodmissing/170241 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| if (TYPE(a) == T_STRING && RBASIC(a)->klass == rb_cString && | |
| TYPE(b) == T_STRING && RBASIC(b)->klass == rb_cString) { | |
| return rb_str_cmp(a, b); | |
| } | |
| if (a == Qundef || b == Qundef) return -1; | |
| if (SYMBOL_P(a) && SYMBOL_P(b)) { | |
| return a != b; | |
| } | |
| args[0] = a; | |
| args[1] = b; | |
| return !rb_with_disable_interrupt(eql, (VALUE)args); | |
| } | |
| VALUE | |
| rb_hash(obj) | |
| VALUE obj; | |
| { | |
| return rb_funcall(obj, id_hash, 0); | |
| } | |
| static int | |
| rb_any_hash(a) | |
| VALUE a; | |
| { | |
| VALUE hval; | |
| switch (TYPE(a)) { | |
| case T_FIXNUM: | |
| case T_SYMBOL: | |
| return (int)a; | |
| break; | |
| case T_STRING: | |
| return rb_str_hash(a); | |
| break; | |
| default: | |
| hval = rb_funcall(a, id_hash, 0); | |
| if (!FIXNUM_P(hval)) { | |
| hval = rb_funcall(hval, '%', 1, INT2FIX(536870923)); | |
| } | |
| return (int)FIX2LONG(hval); | |
| } | |
| } | |
| static struct st_hash_type objhash = { | |
| rb_any_cmp, | |
| rb_any_hash, | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment