Recently I found some logic redundancy in string_bitwise_or
and this seems like I quite forgot to correct that in my just now
sent patch. Sorry.


Index: string.c
===================================================================
RCS file: /cvs/public/parrot/string.c,v
retrieving revision 1.141
diff -r1.141 string.c
1008,1012c1008
< len = s1 ? s1->bufused : 0;
< if (s2 && s2->bufused < len)
< len = s2->bufused;
< 
< if (dest && *dest)
---
> if (dest && *dest)
1033c1029
< /* get the real len after trancode */
---
> 
1037c1033
< if (!dest || *dest)
---
> if (!dest || !*dest)
1039c1035,1037
< 
---
> else if (res->bufused < len)
> string_grow(interpreter, res, len - res->bufused);
> 
1072c1070,1094
< len = s1 ? s1->bufused : 0;
---
> if (dest && *dest)
> res = *dest;
> else if (!s1 && !s2)
> res = string_make(interpreter, NULL, 0, NULL, 0, NULL);
> 
> if (!s1 && !s2) {
> res->bufused = 0;
> res->strlen = 0;
> return res;
> }
> 
> /* trigger GC for debug */
> if (interpreter && GC_DEBUG(interpreter))
> Parrot_do_dod_run(interpreter, 1);
> 
> if (s1 && s2) {
> if (s1->type != s2->type || s1->encoding != s2->encoding) {
> s1 = string_transcode(interpreter, s1, NULL, string_unicode_type,
> NULL);
> s2 = string_transcode(interpreter, s2, NULL, string_unicode_type,
> NULL);
> }
> }
> 
> len = s1 ? s1->bufused: 0;
1074a1097,1150
> if (!dest || !*dest)
> res = string_make(interpreter, NULL, len,
> s1 ? s1->encoding : NULL, 0, s1 ? s1->type : NULL);
> else if (res->bufused < len)
> string_grow(interpreter, res, len - res->bufused);
> 
> if (s1) {
> s1start = s1->strstart;
> s1end = s1start + s1->bufused;
> res->strlen = s1->strlen;
> }
> else
> s1start = s1end = NULL;
> if (s2) {
> s2start = s2->strstart;
> s2end = s2start + s2->bufused;
> if (!s1 || s2->strlen > s1->strlen)
> res->strlen = s2->strlen;
> }
> else
> s2start = s2end = NULL;
> dp = res->strstart;
> res->bufused = len;
> 
> for ( ; len ; ++s1start, ++s2start, ++dp, --len) {
> if (s1start < s1end && s2start < s2end)
> *dp = *s1start | *s2start;
> else if (s1start < s1end)
> *dp = *s1start;
> else
> *dp = *s2start;
> }
> 
> if (dest)
> *dest = res;
> 
> return res;
> }
> 
> /*=for api string string_bitwise_xor
> * or two strings, performing type and encoding conversions if
> * necessary. If *dest != NULL reuse dest, else create a new result
> */
> STRING *
> string_bitwise_xor(struct Parrot_Interp *interpreter, STRING *s1,
> STRING *s2, STRING **dest)
> {
> const char *s1start;
> const char *s2start;
> const char *s1end;
> const char *s2end;
> char *dp;
> STRING *res;
> size_t len;
1078c1154
< else if (len == 0)
---
> else if (!s1 && !s2)
1080c1156,1157
< if (!len) {
---
> 
> if (!s1 && !s2) {
1097a1175
> 
1106c1184
< 
---
> 
1117c1195
< if ((s1 && s2->strlen > s1->strlen) || !s1)
---
> if (!s1 || s2->strlen > s1->strlen)
1127c1205
< *dp = *s1start | *s2start;
---
> *dp = *s1start ^ *s2start;
1132a1211
> 
1137a1217
> 
Index: string.c
===================================================================
RCS file: /cvs/public/parrot/string.c,v
retrieving revision 1.141
diff -r1.141 string.c
1008,1012c1008
<     len = s1 ? s1->bufused : 0;
<     if (s2 && s2->bufused < len)
<         len = s2->bufused;
< 
<     if (dest && *dest)
---
>    if (dest && *dest)
1033c1029
<     /* get the real len after trancode */
---
>     
1037c1033
<     if (!dest || *dest)
---
>     if (!dest || !*dest)
1039c1035,1037
< 
---
>     else if (res->bufused < len)
>         string_grow(interpreter, res, len - res->bufused);
>     
1072c1070,1094
<     len = s1 ? s1->bufused : 0;
---
>     if (dest && *dest)
>         res = *dest;
>     else if (!s1 && !s2)
>         res = string_make(interpreter, NULL, 0, NULL, 0, NULL);
>     
>     if (!s1 && !s2) {
>         res->bufused = 0;
>         res->strlen = 0;
>         return res;
>     }
> 
>     /* trigger GC for debug */
>     if (interpreter && GC_DEBUG(interpreter))
>         Parrot_do_dod_run(interpreter, 1);
> 
>     if (s1 && s2) {
>         if (s1->type != s2->type || s1->encoding != s2->encoding) {
>             s1 = string_transcode(interpreter, s1, NULL, string_unicode_type,
>                     NULL);
>             s2 = string_transcode(interpreter, s2, NULL, string_unicode_type,
>                     NULL);
>         }
>     }
>     
>     len = s1 ? s1->bufused: 0;
1074a1097,1150
>     if (!dest || !*dest)
>         res = string_make(interpreter, NULL, len,
>                 s1 ? s1->encoding : NULL, 0, s1 ? s1->type : NULL);
>     else if (res->bufused < len)
>         string_grow(interpreter, res, len - res->bufused);
>     
>     if (s1) {
>         s1start = s1->strstart;
>         s1end = s1start + s1->bufused;
>         res->strlen = s1->strlen;
>     }
>     else
>         s1start = s1end = NULL;
>     if (s2) {
>         s2start = s2->strstart;
>         s2end = s2start + s2->bufused;
>         if (!s1 || s2->strlen > s1->strlen)
>             res->strlen = s2->strlen;
>     }
>     else
>         s2start = s2end = NULL;
>     dp = res->strstart;
>     res->bufused = len;
> 
>     for ( ; len ; ++s1start, ++s2start, ++dp, --len) {
>         if (s1start < s1end && s2start < s2end)
>             *dp = *s1start | *s2start;
>         else if (s1start < s1end)
>             *dp = *s1start;
>         else
>             *dp = *s2start;
>     }
> 
>     if (dest)
>         *dest = res;
> 
>     return res;
> }
> 
> /*=for api string string_bitwise_xor
>  * or two strings, performing type and encoding conversions if
>  * necessary. If *dest != NULL reuse dest, else create a new result
>  */
> STRING *
> string_bitwise_xor(struct Parrot_Interp *interpreter, STRING *s1,
>                STRING *s2, STRING **dest)
> {
>     const char *s1start;
>     const char *s2start;
>     const char *s1end;
>     const char *s2end;
>     char *dp;
>     STRING *res;
>     size_t len;
1078c1154
<     else if (len == 0)
---
>     else if (!s1 && !s2)
1080c1156,1157
<     if (!len) {
---
>     
>     if (!s1 && !s2) {
1097a1175
>     
1106c1184
< 
---
>     
1117c1195
<         if ((s1 && s2->strlen > s1->strlen) || !s1)
---
>         if (!s1 || s2->strlen > s1->strlen)
1127c1205
<             *dp = *s1start | *s2start;
---
>             *dp = *s1start ^ *s2start;
1132a1211
> 
1137a1217
> 

Reply via email to