stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r370601 - /incubator/stdcxx/trunk/src/string.cpp
Date Thu, 19 Jan 2006 20:12:49 GMT
Author: sebor
Date: Thu Jan 19 12:12:43 2006
New Revision: 370601

URL: http://svn.apache.org/viewcvs?rev=370601&view=rev
Log:
2006-01-19  Martin Sebor  <sebor@roguewave.com>

	* string.cpp [_RWSTD_NO_MEMCPY] (__rw_memcpy): Corrected logic
	errors in conditionally compiled code.
	[_RWSTD_NO_MEMCHR] (__rw_memchr): Same.
	[_RWSTD_NO_MEMCMP] (__rw_memcmp): Same.
	[_RWSTD_NO_STRLEN] (__rw_strlen): Same(!) 
	[_RWSTD_NO_WMEMCPY] (__rw_wmemcpy): Same.
	[_RWSTD_NO_WMEMCHR] (__rw_wmemchr): Same.
	[_RWSTD_NO_WMEMCMP] (__rw_wmemcmp): Same.
	[_RWSTD_NO_WSTRLEN] (__rw_wcslen): Same.

Modified:
    incubator/stdcxx/trunk/src/string.cpp

Modified: incubator/stdcxx/trunk/src/string.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/src/string.cpp?rev=370601&r1=370600&r2=370601&view=diff
==============================================================================
--- incubator/stdcxx/trunk/src/string.cpp (original)
+++ incubator/stdcxx/trunk/src/string.cpp Thu Jan 19 12:12:43 2006
@@ -157,7 +157,7 @@
 
     const char* csrc = _RWSTD_STATIC_CAST (const char*, src);
 
-    for (char *tmp = _RWSTD_STATIC_CAST (char*, dst); nbytes; ++tmp, --nbytes)
+    for (char *tmp = _RWSTD_STATIC_CAST (char*, dst); nbytes; --nbytes)
         *tmp++ = *csrc++;
 
     return dst;
@@ -215,7 +215,7 @@
     while (nbytes-- > 0 && int (*csrc) != c)
         ++csrc;
 
-    return *csrc == c ? csrc : 0;
+    return int (*csrc) == c ? csrc : 0;
 
 #endif   // _RWSTD_NO_MEMCHR
 
@@ -254,15 +254,16 @@
 
 #else   // if defined (_RWSTD_NO_MEMCMP)
 
-    const char* const cs1 = _RWSTD_STATIC_CAST (const char*, s1);
-    const char* const cs2 = _RWSTD_STATIC_CAST (const char*, s2);
+    typedef unsigned char UChar;
+
+    const UChar* cs1 = _RWSTD_STATIC_CAST (const UChar*, s1);
+    const UChar* cs2 = _RWSTD_STATIC_CAST (const UChar*, s2);
 
-    for (_RWSTD_SIZE_T i = 0; i != nbytes; ++i) {
-        if (cs1 [i] != cs2 [i])
-            return cs1 [i] < cs2 [i] ? -1 : 1;
-    }
+    int result = 0;
 
-    return 0;
+    for ( ; nbytes && !(result = *cs1 - *cs2); ++cs1, ++cs2, --nbytes);
+
+    return result;
 
 #endif   // _RWSTD_NO_MEMCMP
 
@@ -278,12 +279,11 @@
 
 #else   // if defined (_RWSTD_NO_STRLEN)
 
-    _RWSTD_SIZE_T nbytes = 0;
+    const char* const begin = str;
 
-    while (str++)
-        ++nbytes;
+    for (; *str; ++str);
 
-    return nbytes;
+    return size_t (str - begin);
     
 #endif   // _RWSTD_NO_STRLEN
 
@@ -303,7 +303,7 @@
 
 #else   // if defined (_RWSTD_NO_WMEMCPY)
 
-    for (wchar_t *tmp = dst; nwchars; ++tmp, --nwchars)
+    for (wchar_t *tmp = dst; nwchars; --nwchars)
         *tmp++ = *src++;
 
     return dst;
@@ -393,12 +393,11 @@
 
 #else   // if defined (_RWSTD_NO_WMEMCMP)
 
-    for (_RWSTD_SIZE_T i = 0; i != nwchars; ++i) {
-        if (s1 [i] != s2 [i])
-            return s1 [i] < s2 [i] ? -1 : 1;
-    }
+    int result = 0;
+
+    for ( ; nwchars && !(result = *s1 - *s2); ++s1, ++s2, --nwchars);
 
-    return 0;
+    return result;
 
 #endif   // _RWSTD_NO_WMEMCMP
 
@@ -416,12 +415,11 @@
 
 #else   // if defined (_RWSTD_NO_WCSLEN)
 
-    _RWSTD_SIZE_T nwchars = 0;
+    const wchar_t* const begin = wstr;
 
-    while (wstr++)
-        ++nwchars;
+    for (; *wstr; ++wstr);
 
-    return nwchars;
+    return size_t (wstr - begin);
 
 #endif   // _RWSTD_NO_WCSLEN
 



Mime
View raw message