summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-15 02:11:45 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-15 02:11:45 +0000
commit8c8f85ed4f82ab0671b5608d81327b8f51108afe (patch)
tree5bcd2e672b2269d3e68228ae66654f60be216751
parent731504b4d33ef12f21e9fc20fe3d63261af2295f (diff)
* string.c (rb_hash_uint, rb_hash_start, rb_hash_end): use VALUE
rather than unsigned int. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--include/ruby/intern.h8
-rw-r--r--string.c60
3 files changed, 45 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index 20d12be937a..21cdd131ed7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Mar 15 11:11:44 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (rb_hash_uint, rb_hash_start, rb_hash_end): use VALUE
+ rather than unsigned int.
+
Sun Mar 15 11:00:14 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (load_file_internal): stop the timer thread before exec.
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index ddb1b032293..617c11808ea 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -612,10 +612,10 @@ 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);
-unsigned int rb_hash_start(unsigned int);
-unsigned int rb_hash_uint32(unsigned int, unsigned int);
-unsigned int rb_hash_uint(unsigned int, unsigned int);
-unsigned int rb_hash_end(unsigned int);
+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);
int rb_str_hash_cmp(VALUE,VALUE);
int rb_str_comparable(VALUE, VALUE);
diff --git a/string.c b/string.c
index 0e8f2678e82..ebb4ed2036e 100644
--- a/string.c
+++ b/string.c
@@ -1914,8 +1914,8 @@ rb_str_concat(VALUE str1, VALUE str2)
#define MurmurMagic 0x7fd652ad
-static inline unsigned int
-murmur(unsigned int h, unsigned int k, int r)
+static inline unsigned long
+murmur(unsigned long h, unsigned long k, int r)
{
const unsigned int m = MurmurMagic;
#if MURMUR == 1
@@ -1934,8 +1934,8 @@ murmur(unsigned int h, unsigned int k, int r)
}
#define murmur16(h) murmur_step(h, 16)
-static inline unsigned int
-murmur_finish(unsigned int h)
+static inline unsigned long
+murmur_finish(unsigned long h)
{
#if MURMUR == 1
h = murmur(h, 0, 10);
@@ -1950,8 +1950,8 @@ murmur_finish(unsigned int h)
#define murmur_step(h, k) murmur(h, k, 16)
-static unsigned int
-hash(const unsigned char * data, int len, unsigned int h)
+static VALUE
+hash(const unsigned char * data, size_t len, VALUE h)
{
uint32_t t = 0;
@@ -1964,7 +1964,7 @@ hash(const unsigned char * data, int len, unsigned int h)
#endif
if (len >= sizeof(uint32_t)) {
#if !UNALIGNED_WORD_ACCESS
- int align = (VALUE)data % sizeof(uint32_t);
+ int align = (int)((VALUE)data % sizeof(uint32_t));
if (align) {
uint32_t d = 0;
int sl, sr, pack;
@@ -2006,7 +2006,7 @@ hash(const unsigned char * data, int len, unsigned int h)
len -= sizeof(uint32_t);
}
- pack = len < align ? len : align;
+ pack = len < (size_t)align ? (int)len : align;
d = 0;
switch (pack) {
#ifdef WORDS_BIGENDIAN
@@ -2026,7 +2026,7 @@ hash(const unsigned char * data, int len, unsigned int h)
#endif
#if MURMUR == 2
- if (len < align) goto skip_tail;
+ if (len < (size_t)align) goto skip_tail;
#endif
h = murmur_step(h, t);
data += pack;
@@ -2074,59 +2074,71 @@ hash(const unsigned char * data, int len, unsigned int h)
return murmur_finish(h);
}
-unsigned int
-rb_hash_uint32(unsigned int h, unsigned int i)
+VALUE
+rb_hash_uint32(VALUE h, unsigned int i)
{
return murmur_step(h + i, 16);
}
-unsigned int
-rb_hash_uint(unsigned int h, unsigned int i)
+VALUE
+rb_hash_uint(VALUE h, VALUE i)
{
unsigned int v = 0;
h += i;
#ifdef WORDS_BIGENDIAN
-#if SIZEOF_INT*CHAR_BIT > 12*8
+#if SIZEOF_VALUE*CHAR_BIT > 12*8
v = murmur16(v + (h >> 12*8));
#endif
-#if SIZEOF_INT*CHAR_BIT > 8*8
+#if SIZEOF_VALUE*CHAR_BIT > 8*8
v = murmur16(v + (h >> 8*8));
#endif
-#if SIZEOF_INT*CHAR_BIT > 4*8
+#if SIZEOF_VALUE*CHAR_BIT > 4*8
v = murmur16(v + (h >> 4*8));
#endif
#endif
v = murmur16(v + h);
#ifndef WORDS_BIGENDIAN
-#if SIZEOF_INT*CHAR_BIT > 4*8
+#if SIZEOF_VALUE*CHAR_BIT > 4*8
v = murmur16(v + (h >> 4*8));
#endif
-#if SIZEOF_INT*CHAR_BIT > 8*8
+#if SIZEOF_VALUE*CHAR_BIT > 8*8
v = murmur16(v + (h >> 8*8));
#endif
-#if SIZEOF_INT*CHAR_BIT > 12*8
+#if SIZEOF_VALUE*CHAR_BIT > 12*8
v = murmur16(v + (h >> 12*8));
#endif
#endif
return v;
}
-unsigned int
-rb_hash_end(unsigned int h)
+VALUE
+rb_hash_end(VALUE h)
{
h = murmur_step(h, 10);
h = murmur_step(h, 17);
return h;
}
-unsigned int
-rb_hash_start(unsigned int h)
+VALUE
+rb_hash_start(VALUE h)
{
static int hashseed_init = 0;
- static unsigned int hashseed;
+ static VALUE hashseed;
if (!hashseed_init) {
hashseed = rb_genrand_int32();
+#if SIZEOF_VALUE*CHAR_BIT > 4*8
+ hashseed <<= 4*8;
+ hashseed |= rb_genrand_int32();
+#endif
+#if SIZEOF_VALUE*CHAR_BIT > 8*8
+ hashseed <<= 8*8;
+ hashseed |= rb_genrand_int32();
+#endif
+#if SIZEOF_VALUE*CHAR_BIT > 12*8
+ hashseed <<= 12*8;
+ hashseed |= rb_genrand_int32();
+#endif
hashseed_init = 1;
}