From 945a76d97b00f9c0d24b6d14da86b18284316000 Mon Sep 17 00:00:00 2001 From: knu Date: Wed, 11 Oct 2006 12:43:58 +0000 Subject: * 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 --- ext/digest/digest.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'ext/digest/digest.c') 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; -- cgit v1.2.3