develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35350 - branches/strings/src

From:
simon
Date:
January 10, 2009 11:45
Subject:
[svn:parrot] r35350 - branches/strings/src
Message ID:
20090110194501.224CDCB9F9@x12.develooper.com
Author: simon
Date: Sat Jan 10 11:45:00 2009
New Revision: 35350

Modified:
   branches/strings/src/string.c

Log:
Basic DRY refactoring on bitops macro


Modified: branches/strings/src/string.c
==============================================================================
--- branches/strings/src/string.c	(original)
+++ branches/strings/src/string.c	Sat Jan 10 11:45:00 2009
@@ -1585,7 +1585,7 @@
     return res;
 }
 
-#define BITWISE_XOR_STRINGS(type1, type2, restype, s1, s2, res, maxlen) \
+#define BITWISE_OPERATE_STRINGS(type1, type2, restype, s1, s2, res, maxlen, OP) \
 do { \
     const type1 *curr1   = NULL; \
     const type2 *curr2   = NULL; \
@@ -1609,7 +1609,7 @@
     for (; _index < (maxlen) ; ++curr1, ++curr2, ++dp, ++_index) { \
         if (_index < length1) { \
             if (_index < length2) \
-                *dp = *curr1 ^ *curr2; \
+                *dp = *curr1 OP *curr2; \
             else \
                 *dp = *curr1; \
         } \
@@ -1621,39 +1621,10 @@
 
 
 #define BITWISE_OR_STRINGS(type1, type2, restype, s1, s2, res, maxlen) \
-do { \
-    const type1 *curr1   = NULL; \
-    const type2 *curr2   = NULL; \
-    size_t       length1 = 0; \
-    size_t       length2 = 0; \
-    restype     *dp; \
-    size_t       _index; \
- \
-    if (s1) { \
-        curr1   = (type1 *)(s1)->strstart; \
-        length1 = (s1)->strlen; \
-    } \
-    if (s2) { \
-        curr2   = (type2 *)(s2)->strstart; \
-        length2 = (s2)->strlen; \
-    } \
- \
-    dp = (restype *)(res)->strstart; \
-    _index = 0; \
- \
-    for (; _index < (maxlen) ; ++curr1, ++curr2, ++dp, ++_index) { \
-        if (_index < length1) { \
-            if (_index < length2) \
-                *dp = *curr1 | *curr2; \
-            else \
-                *dp = *curr1; \
-        } \
-        else if (_index < length2) { \
-            *dp = *curr2; \
-        } \
-    } \
-} while (0)
+    BITWISE_OPERATE_STRINGS(type1, type2, restype, s1, s2, res, maxlen, | )
 
+#define BITWISE_XOR_STRINGS(type1, type2, restype, s1, s2, res, maxlen) \
+    BITWISE_OPERATE_STRINGS(type1, type2, restype, s1, s2, res, maxlen, ^ )
 
 /*
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About