Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 794d567

Browse files
author
Victor Stinner
committed
any_find_slice() doesn't use callbacks anymore
* Call directly the right find/rfind method: allow inlining functions * Remove Py_LOCAL_CALLBACK (added for any_find_slice)
1 parent a6968ed commit 794d567

2 files changed

Lines changed: 43 additions & 55 deletions

File tree

Include/pyport.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,12 @@ typedef size_t Py_uhash_t;
286286
/* fastest possible local call under MSVC */
287287
#define Py_LOCAL(type) static type __fastcall
288288
#define Py_LOCAL_INLINE(type) static __inline type __fastcall
289-
#define Py_LOCAL_CALLBACK(name) (__fastcall *name)
290289
#elif defined(USE_INLINE)
291290
#define Py_LOCAL(type) static type
292291
#define Py_LOCAL_INLINE(type) static inline type
293-
#define Py_LOCAL_CALLBACK(name) (*name)
294292
#else
295293
#define Py_LOCAL(type) static type
296294
#define Py_LOCAL_INLINE(type) static type
297-
#define Py_LOCAL_CALLBACK(name) (*name)
298295
#endif
299296

300297
/* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks

Objects/unicodeobject.c

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8531,19 +8531,7 @@ PyUnicode_EncodeDecimal(Py_UNICODE *s,
85318531
#include "stringlib/undef.h"
85328532

85338533
static Py_ssize_t
8534-
any_find_slice(Py_ssize_t Py_LOCAL_CALLBACK(ascii)(const Py_UCS1*, Py_ssize_t,
8535-
const Py_UCS1*, Py_ssize_t,
8536-
Py_ssize_t, Py_ssize_t),
8537-
Py_ssize_t Py_LOCAL_CALLBACK(ucs1)(const Py_UCS1*, Py_ssize_t,
8538-
const Py_UCS1*, Py_ssize_t,
8539-
Py_ssize_t, Py_ssize_t),
8540-
Py_ssize_t Py_LOCAL_CALLBACK(ucs2)(const Py_UCS2*, Py_ssize_t,
8541-
const Py_UCS2*, Py_ssize_t,
8542-
Py_ssize_t, Py_ssize_t),
8543-
Py_ssize_t Py_LOCAL_CALLBACK(ucs4)(const Py_UCS4*, Py_ssize_t,
8544-
const Py_UCS4*, Py_ssize_t,
8545-
Py_ssize_t, Py_ssize_t),
8546-
PyObject* s1, PyObject* s2,
8534+
any_find_slice(int direction, PyObject* s1, PyObject* s2,
85478535
Py_ssize_t start,
85488536
Py_ssize_t end)
85498537
{
@@ -8569,21 +8557,41 @@ any_find_slice(Py_ssize_t Py_LOCAL_CALLBACK(ascii)(const Py_UCS1*, Py_ssize_t,
85698557
len1 = PyUnicode_GET_LENGTH(s1);
85708558
len2 = PyUnicode_GET_LENGTH(s2);
85718559

8572-
switch(kind) {
8573-
case PyUnicode_1BYTE_KIND:
8574-
if (PyUnicode_IS_ASCII(s1) && PyUnicode_IS_ASCII(s2))
8575-
result = ascii(buf1, len1, buf2, len2, start, end);
8576-
else
8577-
result = ucs1(buf1, len1, buf2, len2, start, end);
8578-
break;
8579-
case PyUnicode_2BYTE_KIND:
8580-
result = ucs2(buf1, len1, buf2, len2, start, end);
8581-
break;
8582-
case PyUnicode_4BYTE_KIND:
8583-
result = ucs4(buf1, len1, buf2, len2, start, end);
8584-
break;
8585-
default:
8586-
assert(0); result = -2;
8560+
if (direction > 0) {
8561+
switch(kind) {
8562+
case PyUnicode_1BYTE_KIND:
8563+
if (PyUnicode_IS_ASCII(s1) && PyUnicode_IS_ASCII(s2))
8564+
result = asciilib_find_slice(buf1, len1, buf2, len2, start, end);
8565+
else
8566+
result = ucs1lib_find_slice(buf1, len1, buf2, len2, start, end);
8567+
break;
8568+
case PyUnicode_2BYTE_KIND:
8569+
result = ucs2lib_find_slice(buf1, len1, buf2, len2, start, end);
8570+
break;
8571+
case PyUnicode_4BYTE_KIND:
8572+
result = ucs4lib_find_slice(buf1, len1, buf2, len2, start, end);
8573+
break;
8574+
default:
8575+
assert(0); result = -2;
8576+
}
8577+
}
8578+
else {
8579+
switch(kind) {
8580+
case PyUnicode_1BYTE_KIND:
8581+
if (PyUnicode_IS_ASCII(s1) && PyUnicode_IS_ASCII(s2))
8582+
result = asciilib_rfind_slice(buf1, len1, buf2, len2, start, end);
8583+
else
8584+
result = ucs1lib_rfind_slice(buf1, len1, buf2, len2, start, end);
8585+
break;
8586+
case PyUnicode_2BYTE_KIND:
8587+
result = ucs2lib_rfind_slice(buf1, len1, buf2, len2, start, end);
8588+
break;
8589+
case PyUnicode_4BYTE_KIND:
8590+
result = ucs4lib_rfind_slice(buf1, len1, buf2, len2, start, end);
8591+
break;
8592+
default:
8593+
assert(0); result = -2;
8594+
}
85878595
}
85888596

85898597
if (kind1 != kind)
@@ -8752,18 +8760,9 @@ PyUnicode_Find(PyObject *str,
87528760
return -2;
87538761
}
87548762

8755-
if (direction > 0)
8756-
result = any_find_slice(
8757-
asciilib_find_slice, ucs1lib_find_slice,
8758-
ucs2lib_find_slice, ucs4lib_find_slice,
8759-
str, sub, start, end
8760-
);
8761-
else
8762-
result = any_find_slice(
8763-
asciilib_rfind_slice, ucs1lib_rfind_slice,
8764-
ucs2lib_rfind_slice, ucs4lib_rfind_slice,
8765-
str, sub, start, end
8766-
);
8763+
result = any_find_slice(direction,
8764+
str, sub, start, end
8765+
);
87678766

87688767
Py_DECREF(str);
87698768
Py_DECREF(sub);
@@ -10677,9 +10676,7 @@ unicode_find(PyObject *self, PyObject *args)
1067710676
if (PyUnicode_READY(substring) == -1)
1067810677
return NULL;
1067910678

10680-
result = any_find_slice(
10681-
asciilib_find_slice, ucs1lib_find_slice,
10682-
ucs2lib_find_slice, ucs4lib_find_slice,
10679+
result = any_find_slice(1,
1068310680
self, (PyObject*)substring, start, end
1068410681
);
1068510682

@@ -10771,9 +10768,7 @@ unicode_index(PyObject *self, PyObject *args)
1077110768
if (PyUnicode_READY(substring) == -1)
1077210769
return NULL;
1077310770

10774-
result = any_find_slice(
10775-
asciilib_find_slice, ucs1lib_find_slice,
10776-
ucs2lib_find_slice, ucs4lib_find_slice,
10771+
result = any_find_slice(1,
1077710772
self, (PyObject*)substring, start, end
1077810773
);
1077910774

@@ -11784,9 +11779,7 @@ unicode_rfind(PyObject *self, PyObject *args)
1178411779
if (PyUnicode_READY(substring) == -1)
1178511780
return NULL;
1178611781

11787-
result = any_find_slice(
11788-
asciilib_rfind_slice, ucs1lib_rfind_slice,
11789-
ucs2lib_rfind_slice, ucs4lib_rfind_slice,
11782+
result = any_find_slice(-1,
1179011783
self, (PyObject*)substring, start, end
1179111784
);
1179211785

@@ -11820,9 +11813,7 @@ unicode_rindex(PyObject *self, PyObject *args)
1182011813
if (PyUnicode_READY(substring) == -1)
1182111814
return NULL;
1182211815

11823-
result = any_find_slice(
11824-
asciilib_rfind_slice, ucs1lib_rfind_slice,
11825-
ucs2lib_rfind_slice, ucs4lib_rfind_slice,
11816+
result = any_find_slice(-1,
1182611817
self, (PyObject*)substring, start, end
1182711818
);
1182811819

0 commit comments

Comments
 (0)