1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.

a hash value of Object might be Bignum, but it causes many troubles
  expecially the Object is used as a key of a hash.  so I've gave up
  to do so.

* array.c (rb_ary_hash): use above macro.

* bignum.c (rb_big_hash): ditto.

* hash.c (rb_obj_hash, rb_hash_hash): ditto.

* numeric.c (rb_dbl_hash): ditto.

* proc.c (proc_hash): ditto.

* re.c (rb_reg_hash, match_hash): ditto.

* string.c (rb_str_hash_m): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2016-10-04 16:25:01 +00:00
parent 30e856f589
commit c2dd2d268e
9 changed files with 33 additions and 15 deletions

View file

@ -1,3 +1,24 @@
Wed Oct 5 01:19:45 2016 NAKAMURA Usaku <usa@ruby-lang.org>
* internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.
a hash value of Object might be Bignum, but it causes many troubles
expecially the Object is used as a key of a hash. so I've gave up
to do so.
* array.c (rb_ary_hash): use above macro.
* bignum.c (rb_big_hash): ditto.
* hash.c (rb_obj_hash, rb_hash_hash): ditto.
* numeric.c (rb_dbl_hash): ditto.
* proc.c (proc_hash): ditto.
* re.c (rb_reg_hash, match_hash): ditto.
* string.c (rb_str_hash_m): ditto.
Tue Oct 4 12:59:44 2016 Koichi ITO <koic.ito@gmail.com>
* array.c (rb_ary_dig): [DOC] update an example of error message

View file

@ -3927,7 +3927,7 @@ rb_ary_hash(VALUE ary)
h = rb_hash_uint(h, NUM2LONG(n));
}
h = rb_hash_end(h);
return LONG2FIX(h);
return ST2FIX(h);
}
/*

View file

@ -6645,7 +6645,7 @@ rb_big_hash(VALUE x)
st_index_t hash;
hash = rb_memhash(BDIGITS(x), sizeof(BDIGIT)*BIGNUM_LEN(x)) ^ BIGNUM_SIGN(x);
return INT2FIX(hash);
return ST2FIX(hash);
}
/*

4
hash.c
View file

@ -239,7 +239,7 @@ VALUE
rb_obj_hash(VALUE obj)
{
st_index_t hnum = any_hash(obj, objid_hash);
return LONG2FIX(hnum);
return ST2FIX(hnum);
}
int
@ -2277,7 +2277,7 @@ rb_hash_hash(VALUE hash)
rb_hash_foreach(hash, hash_i, (VALUE)&hval);
}
hval = rb_hash_end(hval);
return INT2FIX(hval);
return ST2FIX(hval);
}
static int

View file

@ -323,6 +323,9 @@ ntz_intptr(uintptr_t x) {
VALUE rb_int128t2big(int128_t n);
#endif
#define ST2FIX(h) LONG2FIX((long)(h))
/* arguments must be Fixnum */
static inline VALUE
rb_fix_mul_fix(VALUE x, VALUE y)

View file

@ -1355,7 +1355,7 @@ rb_dbl_hash(double d)
/* normalize -0.0 to 0.0 */
if (d == 0.0) d = 0.0;
hash = rb_memhash(&d, sizeof(d));
return LONG2FIX(hash);
return ST2FIX(hash);
}
VALUE

2
proc.c
View file

@ -1196,7 +1196,7 @@ proc_hash(VALUE self)
hash = rb_hash_start(0);
hash = rb_hash_proc(hash, self);
hash = rb_hash_end(hash);
return LONG2FIX(hash);
return ST2FIX(hash);
}
/*

4
re.c
View file

@ -2888,7 +2888,7 @@ static VALUE
rb_reg_hash(VALUE re)
{
st_index_t hashval = reg_hash(re);
return LONG2FIX(hashval);
return ST2FIX(hashval);
}
static st_index_t
@ -2956,7 +2956,7 @@ match_hash(VALUE match)
hashval = rb_hash_uint(hashval, rb_memhash(regs->beg, regs->num_regs * sizeof(*regs->beg)));
hashval = rb_hash_uint(hashval, rb_memhash(regs->end, regs->num_regs * sizeof(*regs->end)));
hashval = rb_hash_end(hashval);
return LONG2FIX(hashval);
return ST2FIX(hashval);
}
/*

View file

@ -2963,13 +2963,7 @@ static VALUE
rb_str_hash_m(VALUE str)
{
st_index_t hval = rb_str_hash(str);
#if SIZEOF_LONG == SIZEOF_VOIDP
return LONG2FIX((long)hval);
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
return LL2NUM((LONG_LONG)hval);
#else
# error unsupported platform
#endif
return ST2FIX(hval);
}
#define lesser(a,b) (((a)>(b))?(b):(a))