1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-10-21 11:13:54 +03:00

Performance improvement on the instr() function, especially for large

haystacks.

FossilOrigin-Name: ce51f1a2b6a1789a5876e01cf829e45d84f3851d135a2fa5c44a56f948673a60
This commit is contained in:
drh
2019-01-08 15:18:24 +00:00
parent c0f162020e
commit c930b405f0
3 changed files with 12 additions and 8 deletions

View File

@@ -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--;