/ Check-in [1d212957]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Further simplifications to sqlite3VdbeMemSetStr().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:1d212957079a2caa30f3c9d80f43464781bc9634c2b5181a5814efbddae31711
User & Date: drh 2019-02-08 17:28:20
Context
2019-02-08
22:34
Small performance improvement and size reduction for pageFindSlot() - the routine in btree.c that locates a free slot for a cell on a btree page. check-in: 1969372a user: drh tags: trunk
20:55
Use a fast compiler-provided memory barrier exclusively, if such a memory barrier is available. Leaf check-in: df66fec9 user: drh tags: faster-memory-barrier
17:28
Further simplifications to sqlite3VdbeMemSetStr(). check-in: 1d212957 user: drh tags: trunk
15:59
Change the sqlite3VdbeMemGrow() routine so that it no longer guarantees a minimum size of 32 bytes. That minimum is no longer required, and without the extra check for the minimum size, the routine runs faster. check-in: 5c499da8 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbemem.c.

  1041   1041       iLimit = SQLITE_MAX_LENGTH;
  1042   1042     }
  1043   1043     flags = (enc==0?MEM_Blob:MEM_Str);
  1044   1044     if( nByte<0 ){
  1045   1045       assert( enc!=0 );
  1046   1046       if( enc==SQLITE_UTF8 ){
  1047   1047         nByte = 0x7fffffff & (int)strlen(z);
  1048         -      if( nByte>iLimit ) nByte = iLimit+1;
  1049   1048       }else{
  1050   1049         for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
  1051   1050       }
  1052   1051       flags |= MEM_Term;
  1053   1052     }
  1054   1053   
  1055   1054     /* The following block sets the new values of Mem.z and Mem.xDel. It
  1056   1055     ** also sets a flag in local variable "flags" to indicate the memory
  1057   1056     ** management (one of MEM_Dyn or MEM_Static).
  1058   1057     */
  1059   1058     if( xDel==SQLITE_TRANSIENT ){
  1060         -    int nAlloc = nByte;
         1059  +    u32 nAlloc = nByte;
  1061   1060       if( flags&MEM_Term ){
  1062   1061         nAlloc += (enc==SQLITE_UTF8?1:2);
  1063   1062       }
  1064   1063       if( nByte>iLimit ){
  1065   1064         return SQLITE_TOOBIG;
  1066   1065       }
  1067   1066       testcase( nAlloc==0 );
  1068   1067       testcase( nAlloc==31 );
  1069   1068       testcase( nAlloc==32 );
  1070         -    if( sqlite3VdbeMemClearAndResize(pMem, MAX(nAlloc,32)) ){
         1069  +    if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
  1071   1070         return SQLITE_NOMEM_BKPT;
  1072   1071       }
  1073   1072       memcpy(pMem->z, z, nAlloc);
  1074         -  }else if( xDel==SQLITE_DYNAMIC ){
  1075         -    sqlite3VdbeMemRelease(pMem);
  1076         -    pMem->zMalloc = pMem->z = (char *)z;
  1077         -    pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
  1078   1073     }else{
  1079   1074       sqlite3VdbeMemRelease(pMem);
  1080   1075       pMem->z = (char *)z;
  1081         -    pMem->xDel = xDel;
  1082         -    flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
         1076  +    if( xDel==SQLITE_DYNAMIC ){
         1077  +      pMem->zMalloc = pMem->z;
         1078  +      pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
         1079  +    }else{
         1080  +      pMem->xDel = xDel;
         1081  +      flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
         1082  +    }
  1083   1083     }
  1084   1084   
  1085   1085     pMem->n = nByte;
  1086   1086     pMem->flags = flags;
  1087   1087     pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
  1088   1088   
  1089   1089   #ifndef SQLITE_OMIT_UTF16