/ Check-in [84fa069c]
Login

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

Overview
Comment:Slightly smaller and faster implementation for vdbeSorterCompareInt().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 84fa069c5bdfe41d03d03875c9157cc6785150b677c04e40b8916ba5af073dc8
User & Date: drh 2017-04-03 12:04:39
Context
2017-04-03
13:17
Fix typos in the documentation for OP_Column. check-in: 777b43e6 user: drh tags: trunk
12:04
Slightly smaller and faster implementation for vdbeSorterCompareInt(). check-in: 84fa069c user: drh tags: trunk
2017-04-01
20:44
Remove an unnecessary setting of the Mem.enc field for the output of the OP_Record opcode, for a performance improvement and size reduction. check-in: e6e36b28 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbesort.c.

   854    854     const u8 * const v1 = &p1[ p1[0] ];   /* Pointer to value 1 */
   855    855     const u8 * const v2 = &p2[ p2[0] ];   /* Pointer to value 2 */
   856    856     int res;                              /* Return value */
   857    857   
   858    858     assert( (s1>0 && s1<7) || s1==8 || s1==9 );
   859    859     assert( (s2>0 && s2<7) || s2==8 || s2==9 );
   860    860   
   861         -  if( s1>7 && s2>7 ){
          861  +  if( s1==s2 ){
          862  +    /* The two values have the same sign. Compare using memcmp(). */
          863  +    static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8, 0, 0, 0 };
          864  +    const u8 n = aLen[s1];
          865  +    int i;
          866  +    res = 0;
          867  +    for(i=0; i<n; i++){
          868  +      if( (res = v1[i] - v2[i])!=0 ){
          869  +        if( ((v1[0] ^ v2[0]) & 0x80)!=0 ){
          870  +          res = v1[0] & 0x80 ? -1 : +1;
          871  +        }
          872  +        break;
          873  +      }
          874  +    }
          875  +  }else if( s1>7 && s2>7 ){
   862    876       res = s1 - s2;
   863    877     }else{
   864         -    if( s1==s2 ){
   865         -      if( (*v1 ^ *v2) & 0x80 ){
   866         -        /* The two values have different signs */
   867         -        res = (*v1 & 0x80) ? -1 : +1;
   868         -      }else{
   869         -        /* The two values have the same sign. Compare using memcmp(). */
   870         -        static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 };
   871         -        int i;
   872         -        res = 0;
   873         -        for(i=0; i<aLen[s1]; i++){
   874         -          if( (res = v1[i] - v2[i]) ) break;
   875         -        }
   876         -      }
          878  +    if( s2>7 ){
          879  +      res = +1;
          880  +    }else if( s1>7 ){
          881  +      res = -1;
          882  +    }else{
          883  +      res = s1 - s2;
          884  +    }
          885  +    assert( res!=0 );
          886  +
          887  +    if( res>0 ){
          888  +      if( *v1 & 0x80 ) res = -1;
   877    889       }else{
   878         -      if( s2>7 ){
   879         -        res = +1;
   880         -      }else if( s1>7 ){
   881         -        res = -1;
   882         -      }else{
   883         -        res = s1 - s2;
   884         -      }
   885         -      assert( res!=0 );
   886         -
   887         -      if( res>0 ){
   888         -        if( *v1 & 0x80 ) res = -1;
   889         -      }else{
   890         -        if( *v2 & 0x80 ) res = +1;
   891         -      }
          890  +      if( *v2 & 0x80 ) res = +1;
   892    891       }
   893    892     }
   894    893   
   895    894     if( res==0 ){
   896    895       if( pTask->pSorter->pKeyInfo->nField>1 ){
   897    896         res = vdbeSorterCompareTail(
   898    897             pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2