[macruby-changes] [4337] MacRuby/trunk/struct.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jul 8 17:03:01 PDT 2010
Revision: 4337
http://trac.macosforge.org/projects/ruby/changeset/4337
Author: lsansonetti at apple.com
Date: 2010-07-08 17:03:00 -0700 (Thu, 08 Jul 2010)
Log Message:
-----------
support comparison of recursive structs
Modified Paths:
--------------
MacRuby/trunk/struct.c
Modified: MacRuby/trunk/struct.c
===================================================================
--- MacRuby/trunk/struct.c 2010-07-08 23:55:33 UTC (rev 4336)
+++ MacRuby/trunk/struct.c 2010-07-09 00:03:00 UTC (rev 4337)
@@ -813,21 +813,35 @@
*/
static VALUE
+rb_struct_equal_r(VALUE s, VALUE s2, int recur)
+{
+ if (recur) {
+ return Qtrue;
+ }
+ for (int i = 0; i < RSTRUCT_LEN(s); i++) {
+ if (!rb_equal(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) {
+ return Qfalse;
+ }
+ }
+ return Qtrue;
+}
+
+static VALUE
rb_struct_equal(VALUE s, SEL sel, VALUE s2)
{
- long i;
-
- if (s == s2) return Qtrue;
- if (TYPE(s2) != T_STRUCT) return Qfalse;
- if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
+ if (s == s2) {
+ return Qtrue;
+ }
+ if (TYPE(s2) != T_STRUCT) {
+ return Qfalse;
+ }
+ if (rb_obj_class(s) != rb_obj_class(s2)) {
+ return Qfalse;
+ }
if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
rb_bug("inconsistent struct"); /* should never happen */
}
-
- for (i=0; i<RSTRUCT_LEN(s); i++) {
- if (!rb_equal(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse;
- }
- return Qtrue;
+ return rb_exec_recursive(rb_struct_equal_r, s, s2);
}
/*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100708/c971be0c/attachment-0001.html>
More information about the macruby-changes
mailing list