[Python-checkins] cpython: replace(): only call PyUnicode_DATA(u) once

victor.stinner python-checkins at python.org
Tue Apr 9 22:53:05 CEST 2013


http://hg.python.org/cpython/rev/d619a9b7c0df
changeset:   83224:d619a9b7c0df
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Apr 09 22:52:48 2013 +0200
summary:
  replace(): only call PyUnicode_DATA(u) once

files:
  Objects/unicodeobject.c |  9 +++++----
  1 files changed, 5 insertions(+), 4 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9972,7 +9972,7 @@
             Py_UCS4 u1, u2;
             int rkind;
             Py_ssize_t index, pos;
-            char *src;
+            char *src, *rbuf;
 
             u1 = PyUnicode_READ(kind1, buf1, 0);
             pos = findchar(sbuf, PyUnicode_KIND(self), slen, u1, 1);
@@ -9984,8 +9984,9 @@
                 goto error;
             _PyUnicode_FastCopyCharacters(u, 0, self, 0, slen);
             rkind = PyUnicode_KIND(u);
-
-            PyUnicode_WRITE(rkind, PyUnicode_DATA(u), pos, u2);
+            rbuf = PyUnicode_DATA(u);
+
+            PyUnicode_WRITE(rkind, rbuf, pos, u2);
             index = 0;
             src = sbuf;
             while (--maxcount)
@@ -9997,7 +9998,7 @@
                 pos = findchar(src, PyUnicode_KIND(self), slen, u1, 1);
                 if (pos < 0)
                     break;
-                PyUnicode_WRITE(rkind, PyUnicode_DATA(u), index + pos, u2);
+                PyUnicode_WRITE(rkind, rbuf, index + pos, u2);
             }
         }
         else {

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list