aboutsummaryrefslogtreecommitdiffstats
path: root/ext/digest/digest.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-11 12:43:58 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-11 12:43:58 +0000
commit945a76d97b00f9c0d24b6d14da86b18284316000 (patch)
tree081ca1d78f2303a682f338b2605a2da30d19b96f /ext/digest/digest.c
parent76f721470b854fca0139f8aeab472341aade62c9 (diff)
downloadruby-945a76d97b00f9c0d24b6d14da86b18284316000.tar.gz
* ext/digest/digest.c (rb_digest_base_alloc,
rb_digest_base_equal): Simplify the equality check and just compare resulted digests since state-level equality should not be significant. * ext/digest/digest.h: Ditto. * ext/digest/*/*.[ch]: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/digest/digest.c')
-rw-r--r--ext/digest/digest.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index d95f8a6976..dd78739b80 100644
--- a/ext/digest/digest.c
+++ b/ext/digest/digest.c
@@ -151,8 +151,7 @@ rb_digest_base_alloc(VALUE klass)
return Data_Wrap_Struct(klass, 0, free, 0);
}
- /* XXX: An uninitialized buffer may lead ALGO_Equal() to fail */
- pctx = xcalloc(algo->ctx_size, 1);
+ pctx = xmalloc(algo->ctx_size);
algo->init_func(pctx);
obj = Data_Wrap_Struct(klass, 0, free, pctx);
@@ -208,7 +207,7 @@ rb_digest_base_copy(VALUE copy, VALUE obj)
algo = get_digest_base_metadata(rb_obj_class(copy));
if (algo == NULL) {
- /* subclasses must define initialize_copy() */
+ /* initialize_copy() is undefined or something */
rb_notimplement();
}
@@ -375,25 +374,22 @@ rb_digest_base_equal(VALUE self, VALUE other)
VALUE str1, str2;
klass = rb_obj_class(self);
- algo = get_digest_base_metadata(klass);
if (rb_obj_class(other) == klass) {
- void *pctx1, *pctx2;
-
- Data_Get_Struct(self, void, pctx1);
- Data_Get_Struct(other, void, pctx2);
-
- return algo->equal_func(pctx1, pctx2) ? Qtrue : Qfalse;
+ str1 = rb_digest_base_digest(self);
+ str2 = rb_digest_base_digest(other);
+ } else {
+ StringValue(other);
+ str2 = other;
+
+ algo = get_digest_base_metadata(klass);
+
+ if (RSTRING_LEN(str2) == algo->digest_len)
+ str1 = rb_digest_base_digest(self);
+ else
+ str1 = rb_digest_base_hexdigest(self);
}
- StringValue(other);
- str2 = other;
-
- if (RSTRING_LEN(str2) == algo->digest_len)
- str1 = rb_digest_base_digest(self);
- else
- str1 = rb_digest_base_hexdigest(self);
-
if (RSTRING_LEN(str1) == RSTRING_LEN(str2)
&& rb_str_cmp(str1, str2) == 0)
return Qtrue;