diff options
author | drh <drh@noemail.net> | 2019-01-08 15:18:24 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2019-01-08 15:18:24 +0000 |
commit | c930b405f0717d5f8626dd846f3ab1d2a7243195 (patch) | |
tree | 3ad2bd2a0d09c0f48a96cd49f8caae40ab4ef702 /src | |
parent | c0f162020ec27bd7cc93c17f3f7e0e91c72f51e4 (diff) | |
download | sqlite-c930b405f0717d5f8626dd846f3ab1d2a7243195.tar.gz sqlite-c930b405f0717d5f8626dd846f3ab1d2a7243195.zip |
Performance improvement on the instr() function, especially for large
haystacks.
FossilOrigin-Name: ce51f1a2b6a1789a5876e01cf829e45d84f3851d135a2fa5c44a56f948673a60
Diffstat (limited to 'src')
-rw-r--r-- | src/func.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/func.c b/src/func.c index 0504a8f02..11598a7ad 100644 --- a/src/func.c +++ b/src/func.c @@ -201,6 +201,7 @@ static void instrFunc( int typeHaystack, typeNeedle; int N = 1; int isText; + unsigned char firstChar; UNUSED_PARAMETER(argc); typeHaystack = sqlite3_value_type(argv[0]); @@ -219,7 +220,10 @@ static void instrFunc( isText = 1; } if( zNeedle==0 || (nHaystack && zHaystack==0) ) return; - while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){ + firstChar = zNeedle[0]; + while( nNeedle<=nHaystack + && (zHaystack[0]!=firstChar || memcmp(zHaystack, zNeedle, nNeedle)!=0) + ){ N++; do{ nHaystack--; |