Change a few selected functions to macros to speed things up. (CVS 4015)

FossilOrigin-Name: 93f811ec747f6a42daf9ee27cd8b013f248552a1
diff --git a/src/btree.c b/src/btree.c
index 5efdcc1..b3fd1f8 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.381 2007/05/12 10:41:48 danielk1977 Exp $
+** $Id: btree.c,v 1.382 2007/05/16 17:28:43 danielk1977 Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** See the header comment on "btreeInt.h" for additional information.
@@ -419,11 +419,13 @@
 **
 ** This routine works only for pages that do not contain overflow cells.
 */
+#define findCell(pPage, iCell) \
+  ((pPage)->aData + get2byte(&(pPage)->aData[(pPage)->cellOffset+2*(iCell)]))
 u8 *sqlite3BtreeFindCell(MemPage *pPage, int iCell){
   u8 *data = pPage->aData;
   assert( iCell>=0 );
   assert( iCell<get2byte(&data[pPage->hdrOffset+3]) );
-  return data + get2byte(&data[pPage->cellOffset+2*iCell]);
+  return findCell(pPage, iCell);
 }
 
 /*
@@ -444,7 +446,7 @@
       iCell--;
     }
   }
-  return sqlite3BtreeFindCell(pPage, iCell);
+  return findCell(pPage, iCell);
 }
 
 /*
@@ -452,6 +454,9 @@
 ** are two versions of this function.  sqlite3BtreeParseCell() takes a 
 ** cell index as the second argument and sqlite3BtreeParseCellPtr() 
 ** takes a pointer to the body of the cell as its second argument.
+**
+** Within this file, the parseCell() macro can be called instead of
+** sqlite3BtreeParseCellPtr(). Using some compilers, this will be faster.
 */
 void sqlite3BtreeParseCellPtr(
   MemPage *pPage,         /* Page containing the cell */
@@ -519,12 +524,14 @@
     pInfo->nSize = pInfo->iOverflow + 4;
   }
 }
+#define parseCell(pPage, iCell, pInfo) \
+  sqlite3BtreeParseCellPtr((pPage), findCell((pPage), (iCell)), (pInfo))
 void sqlite3BtreeParseCell(
   MemPage *pPage,         /* Page containing the cell */
   int iCell,              /* The cell index.  First cell is 0 */
   CellInfo *pInfo         /* Fill in this structure */
 ){
-  sqlite3BtreeParseCellPtr(pPage, sqlite3BtreeFindCell(pPage, iCell), pInfo);
+  parseCell(pPage, iCell, pInfo);
 }
 
 /*
@@ -1661,7 +1668,7 @@
   nCell = pPage->nCell;
 
   for(i=0; i<nCell; i++){
-    u8 *pCell = sqlite3BtreeFindCell(pPage, i);
+    u8 *pCell = findCell(pPage, i);
 
     rc = ptrmapPutOvflPtr(pPage, pCell);
     if( rc!=SQLITE_OK ){
@@ -1716,7 +1723,7 @@
     nCell = pPage->nCell;
 
     for(i=0; i<nCell; i++){
-      u8 *pCell = sqlite3BtreeFindCell(pPage, i);
+      u8 *pCell = findCell(pPage, i);
       if( eType==PTRMAP_OVERFLOW1 ){
         CellInfo info;
         sqlite3BtreeParseCellPtr(pPage, pCell, &info);
@@ -2455,24 +2462,31 @@
 }
 
 /*
-** Make sure the BtCursor.info field of the given cursor is valid.
-** If it is not already valid, call sqlite3BtreeParseCell() to fill it in.
+** The GET_CELL_INFO() macro. Takes one argument, a pointer to a valid
+** btree cursor (type BtCursor*).  This macro makes sure the BtCursor.info
+** field of the given cursor is valid.  If it is not already valid, call
+** sqlite3BtreeParseCell() to fill it in.
 **
 ** BtCursor.info is a cache of the information in the current cell.
 ** Using this cache reduces the number of calls to sqlite3BtreeParseCell().
 */
-static void getCellInfo(BtCursor *pCur){
-  if( pCur->info.nSize==0 ){
-    sqlite3BtreeParseCell(pCur->pPage, pCur->idx, &pCur->info);
-  }else{
 #ifndef NDEBUG
+  static void assertCellInfo(BtCursor *pCur){
     CellInfo info;
     memset(&info, 0, sizeof(info));
     sqlite3BtreeParseCell(pCur->pPage, pCur->idx, &info);
     assert( memcmp(&info, &pCur->info, sizeof(info))==0 );
-#endif
   }
-}
+#else
+  #define assertCellInfo(x)
+#endif
+
+#define GET_CELL_INFO(pCur)                                             \
+  if( pCur->info.nSize==0 )                                             \
+    sqlite3BtreeParseCell(pCur->pPage, pCur->idx, &pCur->info);         \
+  else                                                                  \
+    assertCellInfo(pCur);
+   
 
 /*
 ** Set *pSize to the size of the buffer needed to hold the value of
@@ -2489,7 +2503,7 @@
     if( pCur->eState==CURSOR_INVALID ){
       *pSize = 0;
     }else{
-      getCellInfo(pCur);
+      GET_CELL_INFO(pCur);
       *pSize = pCur->info.nKey;
     }
   }
@@ -2511,7 +2525,7 @@
       /* Not pointing at a valid entry - set *pSize to 0. */
       *pSize = 0;
     }else{
-      getCellInfo(pCur);
+      GET_CELL_INFO(pCur);
       *pSize = pCur->info.nData;
     }
   }
@@ -2684,7 +2698,7 @@
   assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
   assert( offset>=0 );
 
-  getCellInfo(pCur);
+  GET_CELL_INFO(pCur);
   aPayload = pCur->info.pCell + pCur->info.nHeader;
   nKey = (pPage->intKey ? 0 : pCur->info.nKey);
 
@@ -2874,7 +2888,7 @@
   assert( pCur->eState==CURSOR_VALID );
   pPage = pCur->pPage;
   assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
-  getCellInfo(pCur);
+  GET_CELL_INFO(pCur);
   aPayload = pCur->info.pCell;
   aPayload += pCur->info.nHeader;
   if( pPage->intKey ){
@@ -3045,7 +3059,7 @@
   assert( pCur->eState==CURSOR_VALID );
   while( !(pPage = pCur->pPage)->leaf ){
     assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
-    pgno = get4byte(sqlite3BtreeFindCell(pPage, pCur->idx));
+    pgno = get4byte(findCell(pPage, pCur->idx));
     rc = moveToChild(pCur, pgno);
     if( rc ) return rc;
   }
@@ -3182,7 +3196,7 @@
       pCur->info.nSize = 0;
       if( pPage->intKey ){
         u8 *pCell;
-        pCell = sqlite3BtreeFindCell(pPage, pCur->idx) + pPage->childPtrSize;
+        pCell = findCell(pPage, pCur->idx) + pPage->childPtrSize;
         if( pPage->hasData ){
           u32 dummy;
           pCell += getVarint32(pCell, &dummy);
@@ -3237,7 +3251,7 @@
     }else if( lwr>=pPage->nCell ){
       chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
     }else{
-      chldPg = get4byte(sqlite3BtreeFindCell(pPage, lwr));
+      chldPg = get4byte(findCell(pPage, lwr));
     }
     if( chldPg==0 ){
       assert( pCur->idx>=0 && pCur->idx<pCur->pPage->nCell );
@@ -3364,7 +3378,7 @@
   assert( pPage->isInit );
   assert( pCur->idx>=0 );
   if( !pPage->leaf ){
-    pgno = get4byte( sqlite3BtreeFindCell(pPage, pCur->idx) );
+    pgno = get4byte( findCell(pPage, pCur->idx) );
     rc = moveToChild(pCur, pgno);
     if( rc ) return rc;
     rc = moveToRightmost(pCur);
@@ -3933,7 +3947,7 @@
   if( pPage->leaf ) return SQLITE_OK;
 
   for(i=0; i<pPage->nCell; i++){
-    u8 *pCell = sqlite3BtreeFindCell(pPage, i);
+    u8 *pCell = findCell(pPage, i);
     if( !pPage->leaf ){
       rc = reparentPage(pBt, get4byte(pCell), pPage, i);
       if( rc!=SQLITE_OK ) return rc;
@@ -4187,7 +4201,7 @@
   ** pPage is the next-to-right child. 
   */
   assert( pPage->nCell>0 );
-  pCell = sqlite3BtreeFindCell(pPage, pPage->nCell-1);
+  pCell = findCell(pPage, pPage->nCell-1);
   sqlite3BtreeParseCellPtr(pPage, pCell, &info);
   rc = fillInCell(pParent, parentCell, 0, info.nKey, 0, 0, 0, &parentSize);
   if( rc!=SQLITE_OK ){
@@ -4337,7 +4351,7 @@
     pgno = pPage->pgno;
     assert( pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
     for(idx=0; idx<pParent->nCell; idx++){
-      if( get4byte(sqlite3BtreeFindCell(pParent, idx))==pgno ){
+      if( get4byte(findCell(pParent, idx))==pgno ){
         break;
       }
     }
@@ -4371,7 +4385,7 @@
   nDiv = 0;
   for(i=0, k=nxDiv; i<NB; i++, k++){
     if( k<pParent->nCell ){
-      apDiv[i] = sqlite3BtreeFindCell(pParent, k);
+      apDiv[i] = findCell(pParent, k);
       nDiv++;
       assert( !pParent->leaf );
       pgnoOld[i] = get4byte(apDiv[i]);
@@ -4872,7 +4886,7 @@
         int i;
         zeroPage(pPage, pChild->aData[0]);
         for(i=0; i<pChild->nCell; i++){
-          apCell[i] = sqlite3BtreeFindCell(pChild,i);
+          apCell[i] = findCell(pChild,i);
           szCell[i] = cellSizePtr(pChild, apCell[i]);
         }
         assemblePage(pPage, pChild->nCell, apCell, szCell);
@@ -5105,7 +5119,7 @@
   if( loc==0 && CURSOR_VALID==pCur->eState ){
     int szOld;
     assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
-    oldCell = sqlite3BtreeFindCell(pPage, pCur->idx);
+    oldCell = findCell(pPage, pCur->idx);
     if( !pPage->leaf ){
       memcpy(newCell, oldCell, 4);
     }
@@ -5177,7 +5191,7 @@
   ** data. The clearCell() call frees any overflow pages associated with the
   ** cell. The cell itself is still intact.
   */
-  pCell = sqlite3BtreeFindCell(pPage, pCur->idx);
+  pCell = findCell(pPage, pCur->idx);
   if( !pPage->leaf ){
     pgnoChild = get4byte(pCell);
   }
@@ -5209,7 +5223,7 @@
       TRACE(("DELETE: table=%d delete internal from %d replace from leaf %d\n",
          pCur->pgnoRoot, pPage->pgno, leafCur.pPage->pgno));
       dropCell(pPage, pCur->idx, cellSizePtr(pPage, pCell));
-      pNext = sqlite3BtreeFindCell(leafCur.pPage, leafCur.idx);
+      pNext = findCell(leafCur.pPage, leafCur.idx);
       szNext = cellSizePtr(leafCur.pPage, pNext);
       assert( MX_CELL_SIZE(pBt)>=szNext+4 );
       tempCell = sqliteMallocRaw( MX_CELL_SIZE(pBt) );
@@ -5400,7 +5414,7 @@
   rc = getAndInitPage(pBt, pgno, &pPage, pParent);
   if( rc ) goto cleardatabasepage_out;
   for(i=0; i<pPage->nCell; i++){
-    pCell = sqlite3BtreeFindCell(pPage, i);
+    pCell = findCell(pPage, i);
     if( !pPage->leaf ){
       rc = clearDatabasePage(pBt, get4byte(pCell), pPage->pParent, 1);
       if( rc ) goto cleardatabasepage_out;
@@ -5887,7 +5901,7 @@
     */
     sqlite3_snprintf(sizeof(zContext), zContext,
              "On tree page %d cell %d: ", iPage, i);
-    pCell = sqlite3BtreeFindCell(pPage,i);
+    pCell = findCell(pPage,i);
     sqlite3BtreeParseCellPtr(pPage, pCell, &info);
     sz = info.nData;
     if( !pPage->intKey ) sz += info.nKey;
diff --git a/src/btreeInt.h b/src/btreeInt.h
index abd5ed7..89af4e4 100644
--- a/src/btreeInt.h
+++ b/src/btreeInt.h
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btreeInt.h,v 1.3 2007/05/16 14:23:00 danielk1977 Exp $
+** $Id: btreeInt.h,v 1.4 2007/05/16 17:28:43 danielk1977 Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** For a detailed discussion of BTrees, refer to
@@ -570,9 +570,9 @@
 /*
 ** Read or write a two- and four-byte big-endian integer values.
 */
-#define get2byte(x) ((x)[0]<<8 | (x)[1])
+#define get2byte(x)   ((x)[0]<<8 | (x)[1])
+#define put2byte(p,v) ((p)[0] = (v)>>8, (p)[1] = (v))
 #define get4byte sqlite3Get4byte
-#define put2byte sqlite3Put2byte
 #define put4byte sqlite3Put4byte
 
 /*
diff --git a/src/malloc.c b/src/malloc.c
index 524f5ea..e8124a3 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -12,7 +12,7 @@
 ** Memory allocation functions used throughout sqlite.
 **
 **
-** $Id: malloc.c,v 1.1 2007/05/05 11:48:54 drh Exp $
+** $Id: malloc.c,v 1.2 2007/05/16 17:28:43 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -788,10 +788,10 @@
 ** then the connection error-code (the value returned by sqlite3_errcode())
 ** is set to SQLITE_NOMEM.
 */
-static int mallocHasFailed = 0;
+int sqlite3_mallocHasFailed = 0;
 int sqlite3ApiExit(sqlite3* db, int rc){
   if( sqlite3MallocFailed() ){
-    mallocHasFailed = 0;
+    sqlite3_mallocHasFailed = 0;
     sqlite3OsLeaveMutex();
     sqlite3Error(db, SQLITE_NOMEM, 0);
     rc = SQLITE_NOMEM;
@@ -800,21 +800,13 @@
 }
 
 /* 
-** Return true is a malloc has failed in this thread since the last call
-** to sqlite3ApiExit(), or false otherwise.
-*/
-int sqlite3MallocFailed(){
-  return (mallocHasFailed && sqlite3OsInMutex(1));
-}
-
-/* 
 ** Set the "malloc has failed" condition to true for this thread.
 */
 void sqlite3FailedMalloc(){
   if( !sqlite3MallocFailed() ){
     sqlite3OsEnterMutex();
-    assert( mallocHasFailed==0 );
-    mallocHasFailed = 1;
+    assert( sqlite3_mallocHasFailed==0 );
+    sqlite3_mallocHasFailed = 1;
   }
 }
 
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 1b831f2..3f28e14 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.568 2007/05/15 16:51:37 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.569 2007/05/16 17:28:43 danielk1977 Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -254,10 +254,19 @@
 
 #endif
 
+/* Variable sqlite3_mallocHasFailed is set to true after a malloc() 
+** failure occurs. 
+**
+** The sqlite3MallocFailed() macro returns true if a malloc has failed
+** in this thread since the last call to sqlite3ApiExit(), or false 
+** otherwise.
+*/
+extern int sqlite3_mallocHasFailed;
+#define sqlite3MallocFailed() (sqlite3_mallocHasFailed && sqlite3OsInMutex(1))
+
 #define sqliteFree(x)          sqlite3FreeX(x)
 #define sqliteAllocSize(x)     sqlite3AllocSize(x)
 
-
 /*
 ** An instance of this structure might be allocated to store information
 ** specific to a single thread.
@@ -333,6 +342,8 @@
 typedef struct WhereInfo WhereInfo;
 typedef struct WhereLevel WhereLevel;
 
+#include "os.h"
+
 /*
 ** Each database file to be accessed by the system is an instance
 ** of the following structure.  There are normally two of these structures
@@ -1878,7 +1889,6 @@
   void (*)(sqlite3_context*,int,sqlite3_value **),
   void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*));
 int sqlite3ApiExit(sqlite3 *db, int);
-int sqlite3MallocFailed(void);
 void sqlite3FailedMalloc(void);
 void sqlite3AbortOtherActiveVdbes(sqlite3 *, Vdbe *);
 int sqlite3OpenTempDatabase(Parse *);
diff --git a/src/util.c b/src/util.c
index 8d942b0..031c07b 100644
--- a/src/util.c
+++ b/src/util.c
@@ -14,7 +14,7 @@
 ** This file contains functions for allocating memory, comparing
 ** strings, and stuff like that.
 **
-** $Id: util.c,v 1.203 2007/05/15 16:51:37 drh Exp $
+** $Id: util.c,v 1.204 2007/05/16 17:28:43 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -537,18 +537,11 @@
 
 
 /*
-** Read or write a two- and four-byte big-endian integer values.
+** Read or write a four-byte big-endian integer value.
 */
-u32 sqlite3Get2byte(const u8 *p){
-  return (p[0]<<8) | p[1];
-}
 u32 sqlite3Get4byte(const u8 *p){
   return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
 }
-void sqlite3Put2byte(unsigned char *p, u32 v){
-  p[0] = v>>8;
-  p[1] = v;
-}
 void sqlite3Put4byte(unsigned char *p, u32 v){
   p[0] = v>>24;
   p[1] = v>>16;
diff --git a/src/vdbe.c b/src/vdbe.c
index a8aad0c..a9f19ad 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.620 2007/05/16 14:23:00 danielk1977 Exp $
+** $Id: vdbe.c,v 1.621 2007/05/16 17:28:43 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -152,6 +152,12 @@
        && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
 
 /*
+** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
+** P if required.
+*/
+#define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
+
+/*
 ** Argument pMem points at a memory cell that will be passed to a
 ** user-defined function or returned to the user as the result of a query.
 ** The second argument, 'db_enc' is the text encoding used by the vdbe for
@@ -1470,7 +1476,7 @@
   assert( MEM_Str==(MEM_Blob>>3) );
   pTos->flags |= (pTos->flags&MEM_Blob)>>3;
   applyAffinity(pTos, SQLITE_AFF_TEXT, encoding);
-  rc = sqlite3VdbeMemExpandBlob(pTos);
+  rc = ExpandBlob(pTos);
   assert( pTos->flags & MEM_Str );
   pTos->flags &= ~(MEM_Int|MEM_Real|MEM_Blob);
   break;
@@ -1675,8 +1681,8 @@
   }
 
   assert( pOp->p3type==P3_COLLSEQ || pOp->p3==0 );
-  sqlite3VdbeMemExpandBlob(pNos);
-  sqlite3VdbeMemExpandBlob(pTos);
+  ExpandBlob(pNos);
+  ExpandBlob(pTos);
   res = sqlite3MemCompare(pNos, pTos, (CollSeq*)pOp->p3);
   switch( pOp->opcode ){
     case OP_Eq:    res = res==0;     break;
@@ -2275,7 +2281,7 @@
       containsNull = 1;
     }
     if( pRec->flags&MEM_Zero && pRec->n>0 ){
-      sqlite3VdbeMemExpandBlob(pRec);
+      ExpandBlob(pRec);
     }
     serial_type = sqlite3VdbeSerialType(pRec, file_format);
     len = sqlite3VdbeSerialTypeLen(serial_type);
@@ -2928,7 +2934,7 @@
       pC->rowidIsValid = res==0;
     }else{
       assert( pTos->flags & MEM_Blob );
-      sqlite3VdbeMemExpandBlob(pTos);
+      ExpandBlob(pTos);
       rc = sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, 0, &res);
       if( rc!=SQLITE_OK ){
         goto abort_due_to_error;
@@ -3831,7 +3837,7 @@
   assert( pTos->flags & MEM_Blob );
   if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
     assert( pC->isTable==0 );
-    rc = sqlite3VdbeMemExpandBlob(pTos);
+    rc = ExpandBlob(pTos);
     if( rc==SQLITE_OK ){
       int nKey = pTos->n;
       const char *zKey = pTos->z;
@@ -3967,7 +3973,7 @@
  
     assert( pTos->flags & MEM_Blob );  /* Created using OP_MakeRecord */
     assert( pC->deferredMoveto==0 );
-    sqlite3VdbeMemExpandBlob(pTos);
+    ExpandBlob(pTos);
     *pC->pIncrKey = pOp->p3!=0;
     assert( pOp->p3==0 || pOp->opcode!=OP_IdxGT );
     rc = sqlite3VdbeIdxKeyCompare(pC, pTos->n, (u8*)pTos->z, &res);
diff --git a/src/vdbemem.c b/src/vdbemem.c
index 5d8d2b8..f65ac6a 100644
--- a/src/vdbemem.c
+++ b/src/vdbemem.c
@@ -22,6 +22,12 @@
 #include "vdbeInt.h"
 
 /*
+** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
+** P if required.
+*/
+#define expandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
+
+/*
 ** If pMem is an object with a valid string representation, this routine
 ** ensures the internal encoding for the string representation is
 ** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
@@ -63,7 +69,7 @@
 int sqlite3VdbeMemDynamicify(Mem *pMem){
   int n;
   u8 *z;
-  sqlite3VdbeMemExpandBlob(pMem);
+  expandBlob(pMem);
   if( (pMem->flags & (MEM_Ephem|MEM_Static|MEM_Short))==0 ){
     return SQLITE_OK;
   }
@@ -120,7 +126,7 @@
 int sqlite3VdbeMemMakeWriteable(Mem *pMem){
   int n;
   u8 *z;
-  sqlite3VdbeMemExpandBlob(pMem);
+  expandBlob(pMem);
   if( (pMem->flags & (MEM_Ephem|MEM_Static))==0 ){
     return SQLITE_OK;
   }
@@ -836,7 +842,7 @@
   }
   assert( (MEM_Blob>>3) == MEM_Str );
   pVal->flags |= (pVal->flags & MEM_Blob)>>3;
-  sqlite3VdbeMemExpandBlob(pVal);
+  expandBlob(pVal);
   if( pVal->flags&MEM_Str ){
     sqlite3VdbeChangeEncoding(pVal, enc & ~SQLITE_UTF16_ALIGNED);
     if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&(int)pVal->z) ){