diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-08 13:10:04 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-08 13:10:04 +0000 |
commit | 31b7ae00c05aef76416c767df92be45d62e9d06a (patch) | |
tree | 87743fd1893484f1af704d20e3695810ea21a893 /re.c | |
parent | 034414741e4616f7a305f12fe36e1f9a6b0ff074 (diff) | |
download | ruby-31b7ae00c05aef76416c767df92be45d62e9d06a.tar.gz |
* 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
Diffstat (limited to 're.c')
-rw-r--r-- | re.c | 28 |
1 files changed, 13 insertions, 15 deletions
@@ -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))); |