summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2006-05-27 14:58:20 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2006-05-27 14:58:20 (GMT)
commitc2d29c5a6dc701f6fc1dc9b5274053f17c660960 (patch)
treedbd3a26ab83c74ddbe7a6ca59770e56821436d9d /Objects
parent94b8c122fddac469dd6af9ebf7c2eca27f39eb76 (diff)
downloadcpython-c2d29c5a6dc701f6fc1dc9b5274053f17c660960.zip
cpython-c2d29c5a6dc701f6fc1dc9b5274053f17c660960.tar.gz
cpython-c2d29c5a6dc701f6fc1dc9b5274053f17c660960.tar.bz2
needforspeed: replace improvements, changed to Py_LOCAL_INLINE
where appropriate
Diffstat (limited to 'Objects')
-rw-r--r--Objects/stringlib/count.h2
-rw-r--r--Objects/stringlib/fastsearch.h2
-rw-r--r--Objects/stringlib/find.h10
-rw-r--r--Objects/stringlib/partition.h4
-rw-r--r--Objects/stringobject.c32
-rw-r--r--Objects/unicodeobject.c46
6 files changed, 55 insertions, 41 deletions
diff --git a/Objects/stringlib/count.h b/Objects/stringlib/count.h
index 0036f63..0bd02b5 100644
--- a/Objects/stringlib/count.h
+++ b/Objects/stringlib/count.h
@@ -7,7 +7,7 @@
#error must include "stringlib/fastsearch.h" before including this module
#endif
-Py_LOCAL(Py_ssize_t)
+Py_LOCAL_INLINE(Py_ssize_t)
stringlib_count(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len)
{
diff --git a/Objects/stringlib/fastsearch.h b/Objects/stringlib/fastsearch.h
index 3d2f92a..8f79c36 100644
--- a/Objects/stringlib/fastsearch.h
+++ b/Objects/stringlib/fastsearch.h
@@ -17,7 +17,7 @@
#define FAST_COUNT 0
#define FAST_SEARCH 1
-Py_LOCAL(Py_ssize_t)
+Py_LOCAL_INLINE(Py_ssize_t)
fastsearch(const STRINGLIB_CHAR* s, Py_ssize_t n,
const STRINGLIB_CHAR* p, Py_ssize_t m,
int mode)
diff --git a/Objects/stringlib/find.h b/Objects/stringlib/find.h
index 9db633d..9f010c7 100644
--- a/Objects/stringlib/find.h
+++ b/Objects/stringlib/find.h
@@ -7,7 +7,7 @@
#error must include "stringlib/fastsearch.h" before including this module
#endif
-Py_LOCAL(Py_ssize_t)
+Py_LOCAL_INLINE(Py_ssize_t)
stringlib_find(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
Py_ssize_t offset)
@@ -25,7 +25,7 @@ stringlib_find(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
return pos;
}
-Py_LOCAL(Py_ssize_t)
+Py_LOCAL_INLINE(Py_ssize_t)
stringlib_rfind(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
Py_ssize_t offset)
@@ -50,7 +50,7 @@ stringlib_rfind(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
#ifdef STRINGLIB_STR
-Py_LOCAL(Py_ssize_t)
+Py_LOCAL_INLINE(Py_ssize_t)
stringlib_find_obj(PyObject* str, PyObject* sub,
Py_ssize_t start, Py_ssize_t end)
{
@@ -60,7 +60,7 @@ stringlib_find_obj(PyObject* str, PyObject* sub,
);
}
-Py_LOCAL(int)
+Py_LOCAL_INLINE(int)
stringlib_contains_obj(PyObject* str, PyObject* sub)
{
return stringlib_find(
@@ -69,7 +69,7 @@ stringlib_contains_obj(PyObject* str, PyObject* sub)
) != -1;
}
-Py_LOCAL(Py_ssize_t)
+Py_LOCAL_INLINE(Py_ssize_t)
stringlib_rfind_obj(PyObject* str, PyObject* sub,
Py_ssize_t start, Py_ssize_t end)
{
diff --git a/Objects/stringlib/partition.h b/Objects/stringlib/partition.h
index 11a12c6..1486347 100644
--- a/Objects/stringlib/partition.h
+++ b/Objects/stringlib/partition.h
@@ -7,7 +7,7 @@
#error must include "stringlib/fastsearch.h" before including this module
#endif
-Py_LOCAL(PyObject*)
+Py_LOCAL_INLINE(PyObject*)
stringlib_partition(
PyObject* str_obj, const STRINGLIB_CHAR* str, Py_ssize_t str_len,
PyObject* sep_obj, const STRINGLIB_CHAR* sep, Py_ssize_t sep_len
@@ -51,7 +51,7 @@ stringlib_partition(
return out;
}
-Py_LOCAL(PyObject*)
+Py_LOCAL_INLINE(PyObject*)
stringlib_rpartition(
PyObject* str_obj, const STRINGLIB_CHAR* str, Py_ssize_t str_len,
PyObject* sep_obj, const STRINGLIB_CHAR* sep, Py_ssize_t sep_len
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 37c7214..7eab4bd 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -1371,7 +1371,7 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
#define RSKIP_SPACE(s, i) { while (i>=0 && isspace(Py_CHARMASK(s[i]))) i--; }
#define RSKIP_NONSPACE(s, i) { while (i>=0 && !isspace(Py_CHARMASK(s[i]))) i--; }
-Py_LOCAL(PyObject *)
+Py_LOCAL_INLINE(PyObject *)
split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
{
Py_ssize_t i, j, count=0;
@@ -1405,7 +1405,7 @@ split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
return NULL;
}
-Py_LOCAL(PyObject *)
+Py_LOCAL_INLINE(PyObject *)
split_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
{
register Py_ssize_t i, j, count=0;
@@ -1578,7 +1578,7 @@ string_rpartition(PyStringObject *self, PyObject *sep_obj)
);
}
-Py_LOCAL(PyObject *)
+Py_LOCAL_INLINE(PyObject *)
rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
{
Py_ssize_t i, j, count=0;
@@ -1614,7 +1614,7 @@ rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
return NULL;
}
-Py_LOCAL(PyObject *)
+Py_LOCAL_INLINE(PyObject *)
rsplit_char(const char *s, Py_ssize_t len, char ch, Py_ssize_t maxcount)
{
register Py_ssize_t i, j, count=0;
@@ -1828,7 +1828,7 @@ _PyString_Join(PyObject *sep, PyObject *x)
return string_join((PyStringObject *)sep, x);
}
-Py_LOCAL(void)
+Py_LOCAL_INLINE(void)
string_adjust_indices(Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t len)
{
if (*end > len)
@@ -1843,7 +1843,7 @@ string_adjust_indices(Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t len)
*start = 0;
}
-Py_LOCAL(Py_ssize_t)
+Py_LOCAL_INLINE(Py_ssize_t)
string_find_internal(PyStringObject *self, PyObject *args, int dir)
{
const char *s = PyString_AS_STRING(self), *sub;
@@ -1953,7 +1953,7 @@ string_rindex(PyStringObject *self, PyObject *args)
}
-Py_LOCAL(PyObject *)
+Py_LOCAL_INLINE(PyObject *)
do_xstrip(PyStringObject *self, int striptype, PyObject *sepobj)
{
char *s = PyString_AS_STRING(self);
@@ -1986,7 +1986,7 @@ do_xstrip(PyStringObject *self, int striptype, PyObject *sepobj)
}
-Py_LOCAL(PyObject *)
+Py_LOCAL_INLINE(PyObject *)
do_strip(PyStringObject *self, int striptype)
{
char *s = PyString_AS_STRING(self);
@@ -2016,7 +2016,7 @@ do_strip(PyStringObject *self, int striptype)
}
-Py_LOCAL(PyObject *)
+Py_LOCAL_INLINE(PyObject *)
do_argstrip(PyStringObject *self, int striptype, PyObject *args)
{
PyObject *sep = NULL;
@@ -2460,7 +2460,7 @@ return_self(PyStringObject *self)
PyString_GET_SIZE(self));
}
-Py_LOCAL(Py_ssize_t)
+Py_LOCAL_INLINE(Py_ssize_t)
countchar(char *target, int target_len, char c, Py_ssize_t maxcount)
{
Py_ssize_t count=0;
@@ -2514,7 +2514,7 @@ findstring(char *target, Py_ssize_t target_len,
return -1;
}
-Py_LOCAL(Py_ssize_t)
+Py_LOCAL_INLINE(Py_ssize_t)
countstring(char *target, Py_ssize_t target_len,
char *pattern, Py_ssize_t pattern_len,
Py_ssize_t start,
@@ -3335,7 +3335,7 @@ string_expandtabs(PyStringObject *self, PyObject *args)
return u;
}
-Py_LOCAL(PyObject *)
+Py_LOCAL_INLINE(PyObject *)
pad(PyStringObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
{
PyObject *u;
@@ -4096,7 +4096,7 @@ _PyString_Resize(PyObject **pv, Py_ssize_t newsize)
/* Helpers for formatstring */
-Py_LOCAL(PyObject *)
+Py_LOCAL_INLINE(PyObject *)
getnextarg(PyObject *args, Py_ssize_t arglen, Py_ssize_t *p_argidx)
{
Py_ssize_t argidx = *p_argidx;
@@ -4125,7 +4125,7 @@ getnextarg(PyObject *args, Py_ssize_t arglen, Py_ssize_t *p_argidx)
#define F_ALT (1<<3)
#define F_ZERO (1<<4)
-Py_LOCAL(int)
+Py_LOCAL_INLINE(int)
formatfloat(char *buf, size_t buflen, int flags,
int prec, int type, PyObject *v)
{
@@ -4312,7 +4312,7 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
return result;
}
-Py_LOCAL(int)
+Py_LOCAL_INLINE(int)
formatint(char *buf, size_t buflen, int flags,
int prec, int type, PyObject *v)
{
@@ -4384,7 +4384,7 @@ formatint(char *buf, size_t buflen, int flags,
return (int)strlen(buf);
}
-Py_LOCAL(int)
+Py_LOCAL_INLINE(int)
formatchar(char *buf, size_t buflen, PyObject *v)
{
/* presume that the buffer is at least 2 characters long */
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 1711b2d..3a855b6 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -141,7 +141,7 @@ static BLOOM_MASK bloom_linebreak;
#define BLOOM_LINEBREAK(ch)\
(BLOOM(bloom_linebreak, (ch)) && Py_UNICODE_ISLINEBREAK((ch)))
-Py_LOCAL(BLOOM_MASK) make_bloom_mask(Py_UNICODE* ptr, Py_ssize_t len)
+Py_LOCAL_INLINE(BLOOM_MASK) make_bloom_mask(Py_UNICODE* ptr, Py_ssize_t len)
{
/* calculate simple bloom-style bitmask for a given unicode string */
@@ -155,7 +155,7 @@ Py_LOCAL(BLOOM_MASK) make_bloom_mask(Py_UNICODE* ptr, Py_ssize_t len)
return mask;
}
-Py_LOCAL(int) unicode_member(Py_UNICODE chr, Py_UNICODE* set, Py_ssize_t setlen)
+Py_LOCAL_INLINE(int) unicode_member(Py_UNICODE chr, Py_UNICODE* set, Py_ssize_t setlen)
{
Py_ssize_t i;
@@ -2015,7 +2015,7 @@ onError:
*/
-Py_LOCAL(const Py_UNICODE *) findchar(const Py_UNICODE *s,
+Py_LOCAL_INLINE(const Py_UNICODE *) findchar(const Py_UNICODE *s,
Py_ssize_t size,
Py_UNICODE ch)
{
@@ -3860,7 +3860,7 @@ int PyUnicode_EncodeDecimal(Py_UNICODE *s,
#define STRINGLIB_NEW PyUnicode_FromUnicode
#define STRINGLIB_STR PyUnicode_AS_UNICODE
-Py_LOCAL(int)
+Py_LOCAL_INLINE(int)
STRINGLIB_CMP(const Py_UNICODE* str, const Py_UNICODE* other, Py_ssize_t len)
{
if (str[0] != other[0])
@@ -4710,7 +4710,7 @@ PyObject *replace(PyUnicodeObject *self,
}
} else {
- Py_ssize_t n, i;
+ Py_ssize_t n, i, j, e;
Py_ssize_t product, new_size, delta;
Py_UNICODE *p;
@@ -4743,21 +4743,35 @@ PyObject *replace(PyUnicodeObject *self,
return NULL;
i = 0;
p = u->str;
+ e = self->length - str1->length;
if (str1->length > 0) {
- while (i <= self->length - str1->length)
- if (Py_UNICODE_MATCH(self, i, str1)) {
- /* replace string segment */
+ while (n-- > 0) {
+ /* look for next match */
+ j = i;
+ while (j <= e) {
+ if (Py_UNICODE_MATCH(self, j, str1))
+ break;
+ j++;
+ }
+ if (j > i) {
+ if (j > e)
+ break;
+ /* copy unchanged part [i:j] */
+ Py_UNICODE_COPY(p, self->str+i, j-i);
+ p += j - i;
+ }
+ /* copy substitution string */
+ if (str2->length > 0) {
Py_UNICODE_COPY(p, str2->str, str2->length);
p += str2->length;
- i += str1->length;
- if (--n <= 0) {
- /* copy remaining part */
- Py_UNICODE_COPY(p, self->str+i, self->length-i);
- break;
- }
- } else
- *p++ = self->str[i++];
+ }
+ i = j + str1->length;
+ }
+ if (i < self->length)
+ /* copy tail [i:] */
+ Py_UNICODE_COPY(p, self->str+i, self->length-i);
} else {
+ /* interleave */
while (n > 0) {
Py_UNICODE_COPY(p, str2->str, str2->length);
p += str2->length;