From 3d885e0195531cd6ea0d8cd22897b4ea978f98a2 Mon Sep 17 00:00:00 2001 From: Fredrik Lundh Date: Tue, 23 May 2006 10:10:57 +0000 Subject: [PATCH] needforspeed: check first *and* last character before doing a full memcmp --- Include/unicodeobject.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index c0036bf837e..82a02327590 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" {