diff options
author | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-23 10:10:57 (GMT) |
---|---|---|
committer | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-23 10:10:57 (GMT) |
commit | 3d885e0195531cd6ea0d8cd22897b4ea978f98a2 (patch) | |
tree | a140b8b4d80a51c980dea87933e5773cd3ec431d /Include | |
parent | 1bacc641a03cb8bc8590b19714d74c32867e39d5 (diff) | |
download | cpython-3d885e0195531cd6ea0d8cd22897b4ea978f98a2.zip cpython-3d885e0195531cd6ea0d8cd22897b4ea978f98a2.tar.gz cpython-3d885e0195531cd6ea0d8cd22897b4ea978f98a2.tar.bz2 |
needforspeed: check first *and* last character before doing a full memcmp
Diffstat (limited to 'Include')
-rw-r--r-- | Include/unicodeobject.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index c0036bf..82a0232 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -367,10 +367,12 @@ typedef PY_UNICODE_TYPE Py_UNICODE; for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\ } while (0) -#define Py_UNICODE_MATCH(string, offset, substring)\ - ((*((string)->str + (offset)) == *((substring)->str)) &&\ - !memcmp((string)->str + (offset), (substring)->str,\ - (substring)->length*sizeof(Py_UNICODE))) +/* check if substring matches at given offset. the offset must be + valid, and the substring must not be empty */ +#define Py_UNICODE_MATCH(string, offset, substring) \ + ((*((string)->str + (offset)) == *((substring)->str)) && \ + ((*((string)->str + (offset) + (substring)->length-1) == *((substring)->str + (substring)->length-1))) && \ + !memcmp((string)->str + (offset), (substring)->str, (substring)->length*sizeof(Py_UNICODE))) #ifdef __cplusplus extern "C" { |