From: Fredrik Lundh Date: Tue, 23 May 2006 10:10:57 +0000 (+0000) Subject: needforspeed: check first *and* last character before doing a full memcmp X-Git-Tag: v2.5b1~591 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d885e0195531cd6ea0d8cd22897b4ea978f98a2;p=python needforspeed: check first *and* last character before doing a full memcmp --- diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index c0036bf837..82a0232759 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" {