aboutsummaryrefslogtreecommitdiffstats
path: root/range.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-17 09:28:46 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-17 09:28:46 +0000
commitbc2df4136536496e72a8bbdf14a8980f65b259b8 (patch)
tree882005fec039591bb92936dad9f76ced7c653763 /range.c
parent2cdcc564fd9a15e8f6d7f20c972cdc6e98243b67 (diff)
downloadruby-bc2df4136536496e72a8bbdf14a8980f65b259b8.tar.gz
* range.c (recursive_hash): extracted from range_hash. reject
recursive key. (range_hash): use recursive_hash. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/range.c b/range.c
index ce2df63100..e013a8a13f 100644
--- a/range.c
+++ b/range.c
@@ -201,21 +201,15 @@ range_eql(VALUE range, VALUE obj)
return Qtrue;
}
-/*
- * call-seq:
- * rng.hash => fixnum
- *
- * Generate a hash value such that two ranges with the same start and
- * end points, and the same value for the "exclude end" flag, generate
- * the same hash value.
- */
-
static VALUE
-range_hash(VALUE range)
+recursive_hash(VALUE range, VALUE dummy, int recur)
{
unsigned long hash = EXCL(range);
VALUE v;
+ if (recur) {
+ rb_raise(rb_eArgError, "recursive key for hash");
+ }
hash = rb_hash_start(hash);
v = rb_hash(RANGE_BEG(range));
hash = rb_hash_uint(hash, NUM2LONG(v));
@@ -227,6 +221,21 @@ range_hash(VALUE range)
return LONG2FIX(hash);
}
+/*
+ * call-seq:
+ * rng.hash => fixnum
+ *
+ * Generate a hash value such that two ranges with the same start and
+ * end points, and the same value for the "exclude end" flag, generate
+ * the same hash value.
+ */
+
+static VALUE
+range_hash(VALUE range)
+{
+ return rb_exec_recursive(recursive_hash, range, 0);
+}
+
static void
range_each_func(VALUE range, VALUE (*func) (VALUE, void *), void *arg)
{