diff options
author | dgp <dgp@noemail.net> | 2011-08-27 02:28:47 (GMT) |
---|---|---|
committer | dgp <dgp@noemail.net> | 2011-08-27 02:28:47 (GMT) |
commit | 51788d8ae7154760d71b8833f9305a5a90393786 (patch) | |
tree | 5481d19a825ee071bc18410c1021c221bc9e88ce /generic/tclStringObj.c | |
parent | 46af4a6ffc03640654ce29e47e9b83f3b95996d8 (diff) | |
download | tcl-51788d8ae7154760d71b8833f9305a5a90393786.zip tcl-51788d8ae7154760d71b8833f9305a5a90393786.tar.gz tcl-51788d8ae7154760d71b8833f9305a5a90393786.tar.bz2 |
Repaired the lost performance in the copy loop hotspots. Now meets or
beats the former trunk (and current trunk by magnitudes) in tclbench.
FossilOrigin-Name: 34daf5b5b37cfe8bb11d71642c5e4b464d8e9ff1
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r-- | generic/tclStringObj.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 27480c5..bccd28a 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -2660,18 +2660,17 @@ ReverseBytes( int count) /* Until this many are copied, */ /* reversing as you go. */ { + unsigned char *src = from + count - 1; if (to == from) { /* Reversing in place */ - from += count - 1; - while (to < from) { - unsigned char c = *from; - *from-- = *to; + while (to < src) { + unsigned char c = *src; + *src-- = *to; *to++ = c; } } else { - from += count - 1; - while (count--) { - *to++ = *from--; + while (src >= from) { + *to++ = *src--; } } } @@ -2683,18 +2682,18 @@ ReverseUniChars( unsigned int count) /* Until this many are copied, */ /* reversing as you go. */ { + Tcl_UniChar *src = from + count - 1; if (to == from) { /* Reversing in place */ from += count - 1; - while (to < from) { - Tcl_UniChar c = *from; - *from-- = *to; + while (to < src) { + Tcl_UniChar c = *src; + *src-- = *to; *to++ = c; } } else { - from += count - 1; - while (count--) { - *to++ = *from--; + while (src >= from) { + *to++ = *src--; } } } |