Permalink
Browse files

* include/ruby/st.h (st_hash_func): use st_index_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 0344147 commit 31b7ae00c05aef76416c767df92be45d62e9d06a @nobu nobu committed Sep 8, 2009
Showing with 92 additions and 79 deletions.
  1. +4 −0 ChangeLog
  2. +2 −1 array.c
  3. +1 −1 bignum.c
  4. +3 −3 compile.c
  5. +1 −1 complex.c
  6. +4 −4 enc/unicode.c
  7. +5 −5 hash.c
  8. +2 −2 include/ruby/intern.h
  9. +4 −4 include/ruby/st.h
  10. +2 −1 io.c
  11. +1 −1 numeric.c
  12. +1 −1 object.c
  13. +10 −8 proc.c
  14. +1 −1 range.c
  15. +1 −1 rational.c
  16. +13 −15 re.c
  17. +2 −2 regparse.c
  18. +9 −9 st.c
  19. +15 −15 string.c
  20. +1 −1 struct.c
  21. +10 −3 thread.c
View
@@ -1,3 +1,7 @@
+Tue Sep 8 22:10:02 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * include/ruby/st.h (st_hash_func): use st_index_t.
+
Tue Sep 8 21:48:15 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm.c (rb_thread_mark): mark callers iseqs. [ruby-core:25474]
View
@@ -2880,7 +2880,8 @@ rb_ary_eql(VALUE ary1, VALUE ary2)
static VALUE
recursive_hash(VALUE ary, VALUE dummy, int recur)
{
- long i, h;
+ long i;
+ st_index_t h;
VALUE n;
if (recur) {
View
@@ -3143,7 +3143,7 @@ rb_big_aref(VALUE x, VALUE y)
static VALUE
rb_big_hash(VALUE x)
{
- int hash;
+ st_index_t hash;
hash = rb_memhash(BDIGITS(x), sizeof(BDIGIT)*RBIGNUM_LEN(x)) ^ RBIGNUM_SIGN(x);
return INT2FIX(hash);
View
@@ -1233,14 +1233,14 @@ cdhash_cmp(VALUE val, VALUE lit)
return !rb_eql(lit, val);
}
-static int
+static st_index_t
cdhash_hash(VALUE a)
{
- if (SPECIAL_CONST_P(a)) return (int)a;
+ if (SPECIAL_CONST_P(a)) return (st_index_t)a;
if (TYPE(a) == T_STRING) return rb_str_hash(a);
{
VALUE hval = rb_hash(a);
- return (int)FIX2LONG(hval);
+ return (st_index_t)FIX2LONG(hval);
}
}
View
@@ -1156,7 +1156,7 @@ nucomp_numerator(VALUE self)
static VALUE
nucomp_hash(VALUE self)
{
- long v, h[2];
+ st_index_t v, h[2];
VALUE n;
get_dat1(self);
View
@@ -2122,10 +2122,10 @@ code2_cmp(OnigCodePoint* x, OnigCodePoint* y)
return 1;
}
-static int
+static st_index_t
code2_hash(OnigCodePoint* x)
{
- return (int )(x[0] + x[1]);
+ return (st_index_t )(x[0] + x[1]);
}
static const struct st_hash_type type_code2_hash = {
@@ -2140,10 +2140,10 @@ code3_cmp(OnigCodePoint* x, OnigCodePoint* y)
return 1;
}
-static int
+static st_index_t
code3_hash(OnigCodePoint* x)
{
- return (int )(x[0] + x[1] + x[2]);
+ return (st_index_t )(x[0] + x[1] + x[2]);
}
static const struct st_hash_type type_code3_hash = {
View
10 hash.c
@@ -72,11 +72,11 @@ rb_hash(VALUE obj)
}
}
-static int
+static st_index_t
rb_any_hash(VALUE a)
{
VALUE hval;
- VALUE hnum;
+ st_index_t hnum;
switch (TYPE(a)) {
case T_FIXNUM:
@@ -96,7 +96,7 @@ rb_any_hash(VALUE a)
hnum = FIX2LONG(hval);
}
hnum <<= 1;
- return (int)RSHIFT(hnum, 1);
+ return (st_index_t)RSHIFT(hnum, 1);
}
static const struct st_hash_type objhash = {
@@ -1544,7 +1544,7 @@ rb_hash_eql(VALUE hash1, VALUE hash2)
static int
hash_i(VALUE key, VALUE val, VALUE arg)
{
- VALUE *hval = (VALUE *)arg;
+ st_index_t *hval = (st_index_t *)arg;
if (key == Qundef) return ST_CONTINUE;
*hval ^= rb_hash_end(rb_hash_uint(rb_hash_start(rb_hash(key)), rb_hash(val)));
@@ -1554,7 +1554,7 @@ hash_i(VALUE key, VALUE val, VALUE arg)
static VALUE
recursive_hash(VALUE hash, VALUE dummy, int recur)
{
- VALUE hval;
+ st_index_t hval;
if (recur) {
rb_raise(rb_eArgError, "recursive key for hash");
View
@@ -633,12 +633,12 @@ VALUE rb_str_cat(VALUE, const char*, long);
VALUE rb_str_cat2(VALUE, const char*);
VALUE rb_str_append(VALUE, VALUE);
VALUE rb_str_concat(VALUE, VALUE);
-int rb_memhash(const void *ptr, long len);
+st_index_t rb_memhash(const void *ptr, long len);
VALUE rb_hash_start(VALUE);
VALUE rb_hash_uint32(VALUE, unsigned int);
VALUE rb_hash_uint(VALUE, VALUE);
VALUE rb_hash_end(VALUE);
-int rb_str_hash(VALUE);
+st_index_t rb_str_hash(VALUE);
int rb_str_hash_cmp(VALUE,VALUE);
int rb_str_comparable(VALUE, VALUE);
int rb_str_cmp(VALUE, VALUE);
View
@@ -55,15 +55,15 @@ typedef unsigned LONG_LONG st_data_t;
typedef struct st_table st_table;
+typedef st_data_t st_index_t;
typedef int st_compare_func(st_data_t, st_data_t);
-typedef int st_hash_func(st_data_t);
+typedef st_index_t st_hash_func(st_data_t);
struct st_hash_type {
int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */
- int (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */
+ st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */
};
-typedef st_data_t st_index_t;
#define ST_INDEX_BITS (sizeof(st_index_t) * CHAR_BIT)
struct st_table {
@@ -104,7 +104,7 @@ void st_cleanup_safe(st_table *, st_data_t);
void st_clear(st_table *);
st_table *st_copy(st_table *);
int st_numcmp(st_data_t, st_data_t);
-int st_numhash(st_data_t);
+st_index_t st_numhash(st_data_t);
int st_strcasecmp(const char *s1, const char *s2);
int st_strncasecmp(const char *s1, const char *s2, size_t n);
size_t st_memsize(st_table *);
View
3 io.c
@@ -6750,6 +6750,7 @@ static VALUE
argf_getline(int argc, VALUE *argv, VALUE argf)
{
VALUE line;
+ int lineno = ARGF.lineno;
retry:
if (!next_argv()) return Qnil;
@@ -6770,7 +6771,7 @@ argf_getline(int argc, VALUE *argv, VALUE argf)
}
}
if (!NIL_P(line)) {
- ARGF.lineno++;
+ ARGF.lineno = ++lineno;
ARGF.last_lineno = ARGF.lineno;
}
return line;
View
@@ -936,7 +936,7 @@ static VALUE
flo_hash(VALUE num)
{
double d;
- int hash;
+ st_index_t hash;
d = RFLOAT_VALUE(num);
/* normalize -0.0 to 0.0 */
View
@@ -99,7 +99,7 @@ VALUE
rb_obj_hash(VALUE obj)
{
VALUE oid = rb_obj_id(obj);
- unsigned long h = rb_hash_end(rb_hash_start(NUM2LONG(oid)));
+ st_index_t h = rb_hash_end(rb_hash_start(NUM2LONG(oid)));
return LONG2NUM(h);
}
View
18 proc.c
@@ -771,12 +771,13 @@ proc_eq(VALUE self, VALUE other)
static VALUE
proc_hash(VALUE self)
{
- long hash;
+ st_index_t hash;
rb_proc_t *proc;
GetProcPtr(self, proc);
- hash = (long)proc->block.iseq;
- hash ^= (long)proc->envval;
- hash ^= (long)proc->block.lfp >> 16;
+ hash = rb_hash_start((st_index_t)proc->block.iseq);
+ hash = rb_hash_uint(hash, (st_index_t)proc->envval);
+ hash = rb_hash_uint(hash, (st_index_t)proc->block.lfp >> 16);
+ hash = rb_hash_end(hash);
return LONG2FIX(hash);
}
@@ -993,12 +994,13 @@ static VALUE
method_hash(VALUE method)
{
struct METHOD *m;
- long hash;
+ st_index_t hash;
TypedData_Get_Struct(method, struct METHOD, &method_data_type, m);
- hash = (long)m->rclass;
- hash ^= (long)m->recv;
- hash ^= (long)m->me.def;
+ hash = rb_hash_start((st_index_t)m->rclass);
+ hash = rb_hash_uint(hash, (st_index_t)m->recv);
+ hash = rb_hash_uint(hash, (st_index_t)m->me.def);
+ hash = rb_hash_end(hash);
return INT2FIX(hash);
}
View
@@ -204,7 +204,7 @@ range_eql(VALUE range, VALUE obj)
static VALUE
recursive_hash(VALUE range, VALUE dummy, int recur)
{
- unsigned long hash = EXCL(range);
+ st_index_t hash = EXCL(range);
VALUE v;
if (recur) {
View
@@ -1495,7 +1495,7 @@ nurat_rationalize(int argc, VALUE *argv, VALUE self)
static VALUE
nurat_hash(VALUE self)
{
- long v, h[2];
+ st_index_t v, h[2];
VALUE n;
get_dat1(self);
View
28 re.c
@@ -2485,6 +2485,7 @@ rb_reg_regcomp(VALUE str)
return reg_cache = rb_reg_new_str(save_str, 0);
}
+static st_index_t reg_hash(VALUE re);
/*
* call-seq:
* rxp.hash => fixnum
@@ -2495,20 +2496,19 @@ rb_reg_regcomp(VALUE str)
static VALUE
rb_reg_hash(VALUE re)
{
- unsigned long hashval;
- long len;
- char *p;
+ st_index_t hashval;
+ return LONG2FIX(hashval);
+}
+
+static st_index_t
+reg_hash(VALUE re)
+{
+ st_index_t hashval;
rb_reg_check(re);
hashval = RREGEXP(re)->ptr->options;
- len = RREGEXP_SRC_LEN(re);
- p = RREGEXP_SRC_PTR(re);
- while (len--) {
- hashval = hashval * 33 + *p++;
- }
- hashval = hashval + (hashval>>5);
-
- return LONG2FIX(hashval);
+ hashval = rb_hash_uint(hashval, rb_memhash(RREGEXP_SRC_PTR(re), RREGEXP_SRC_LEN(re)));
+ return rb_hash_end(hashval);
}
@@ -2555,11 +2555,9 @@ static VALUE
match_hash(VALUE match)
{
const struct re_registers *regs;
- VALUE h;
- unsigned long hashval = rb_hash_start(rb_str_hash(RMATCH(match)->str));
+ st_index_t hashval = rb_hash_start(rb_str_hash(RMATCH(match)->str));
- h = rb_reg_hash(RMATCH(match)->regexp);
- rb_hash_uint(hashval, FIX2LONG(h));
+ rb_hash_uint(hashval, reg_hash(RMATCH(match)->regexp));
regs = RMATCH_REGS(match);
hashval = rb_hash_uint(hashval, regs->num_regs);
hashval = rb_hash_uint(hashval, rb_memhash(regs->beg, regs->num_regs * sizeof(*regs->beg)));
View
@@ -335,7 +335,7 @@ str_end_cmp(st_str_end_key* x, st_str_end_key* y)
return 0;
}
-static int
+static st_index_t
str_end_hash(st_str_end_key* x)
{
UChar *p;
@@ -4937,7 +4937,7 @@ static int type_cclass_cmp(type_cclass_key* x, type_cclass_key* y)
return 0;
}
-static int type_cclass_hash(type_cclass_key* key)
+static st_index_t type_cclass_hash(type_cclass_key* key)
{
int i, val;
UChar *p;
View
18 st.c
@@ -44,13 +44,13 @@ static const struct st_hash_type type_numhash = {
};
/* extern int strcmp(const char *, const char *); */
-static int strhash(const char *);
+static st_index_t strhash(const char *);
static const struct st_hash_type type_strhash = {
strcmp,
strhash,
};
-static int strcasehash(const char *);
+static st_index_t strcasehash(const char *);
static const struct st_hash_type type_strcasehash = {
st_strcasecmp,
strcasehash,
@@ -69,7 +69,7 @@ static void rehash(st_table *);
#define EQUAL(table,x,y) ((x)==(y) || (*table->type->compare)((x),(y)) == 0)
-#define do_hash(key,table) (unsigned int)(*(table)->type->hash)((key))
+#define do_hash(key,table) (unsigned int)(st_index_t)(*(table)->type->hash)((key))
#define do_hash_bin(key,table) (do_hash(key, table)%(table)->num_bins)
/*
@@ -927,10 +927,10 @@ st_reverse_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
*/
#define FNV_32_PRIME 0x01000193
-static int
+static st_index_t
strhash(register const char *string)
{
- register unsigned int hval = FNV1_32A_INIT;
+ register st_index_t hval = FNV1_32A_INIT;
/*
* FNV-1a hash each octet in the buffer
@@ -994,10 +994,10 @@ st_strncasecmp(const char *s1, const char *s2, size_t n)
return 0;
}
-static int
+static st_index_t
strcasehash(register const char *string)
{
- register unsigned int hval = FNV1_32A_INIT;
+ register st_index_t hval = FNV1_32A_INIT;
/*
* FNV-1a hash each octet in the buffer
@@ -1019,8 +1019,8 @@ st_numcmp(st_data_t x, st_data_t y)
return x != y;
}
-int
+st_index_t
st_numhash(st_data_t n)
{
- return (int)n;
+ return (st_index_t)n;
}
Oops, something went wrong.

0 comments on commit 31b7ae0

Please sign in to comment.