Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Modify the assemblePage() function in btree.c so that it runs slightly faster. (CVS 6569) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
7ec42e989f1d4abdc6d52f8feebf5198 |
User & Date: | danielk1977 2009-04-29 17:49:59.000 |
Context
2009-04-29
| ||
18:12 | Fixed compile for MSVC; removed compiler warnings; changes for NDEBUG build; minor code tweaks. (CVS 6570) (check-in: e98b12425f user: shane tags: trunk) | |
17:49 | Modify the assemblePage() function in btree.c so that it runs slightly faster. (CVS 6569) (check-in: 7ec42e989f user: danielk1977 tags: trunk) | |
14:33 | Update the documentation on the sqlite3_changes() and sqlite3_total_changes() functions. (CVS 6568) (check-in: 58c7bdb21c user: drh tags: trunk) | |
Changes
Changes to src/btree.c.
1 2 3 4 5 6 7 8 9 10 11 | /* ** 2004 April 6 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /* ** 2004 April 6 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** $Id: btree.c,v 1.599 2009/04/29 17:49:59 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. ** Including a description of file format and an overview of operation. */ #include "btreeInt.h" |
︙ | ︙ | |||
957 958 959 960 961 962 963 | */ int pc, addr; for(addr=hdr+1; (pc = get2byte(&data[addr]))>0; addr=pc){ int size = get2byte(&data[pc+2]); /* Size of free slot */ if( size>=nByte ){ int x = size - nByte; if( x<4 ){ | | | | | | 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | */ int pc, addr; for(addr=hdr+1; (pc = get2byte(&data[addr]))>0; addr=pc){ int size = get2byte(&data[pc+2]); /* Size of free slot */ if( size>=nByte ){ int x = size - nByte; if( x<4 ){ /* Remove the slot from the free-list. Update the number of ** fragmented bytes within the page. */ memcpy(&data[addr], &data[pc], 2); data[hdr+7] = (u8)(nFrag + x); }else{ /* The slot remains on the free-list. Reduce its size to account ** for the portion used by the new allocation. */ put2byte(&data[pc+2], x); } return pc + x; } } } |
︙ | ︙ | |||
3908 3909 3910 3911 3912 3913 3914 | if( CURSOR_INVALID==pCur->eState ){ assert( pCur->apPage[pCur->iPage]->nCell==0 ); *pRes = 1; }else{ assert( pCur->eState==CURSOR_VALID ); *pRes = 0; rc = moveToRightmost(pCur); | < | 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 | if( CURSOR_INVALID==pCur->eState ){ assert( pCur->apPage[pCur->iPage]->nCell==0 ); *pRes = 1; }else{ assert( pCur->eState==CURSOR_VALID ); *pRes = 0; rc = moveToRightmost(pCur); pCur->atLast = rc==SQLITE_OK ?1:0; } } return rc; } /* Move the cursor so that it points to an entry near the key |
︙ | ︙ | |||
5040 5041 5042 5043 5044 5045 5046 | static void assemblePage( MemPage *pPage, /* The page to be assemblied */ int nCell, /* The number of cells to add to this page */ u8 **apCell, /* Pointers to cell bodies */ u16 *aSize /* Sizes of the cells */ ){ int i; /* Loop counter */ | < < | | > > | < < | < > < < < < | | > | < | | | | | < < | > | < > | 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 | static void assemblePage( MemPage *pPage, /* The page to be assemblied */ int nCell, /* The number of cells to add to this page */ u8 **apCell, /* Pointers to cell bodies */ u16 *aSize /* Sizes of the cells */ ){ int i; /* Loop counter */ u8 *pCellptr; /* Address of next cell pointer */ int cellbody; /* Address of next cell body */ u8 * const data = pPage->aData; /* Pointer to data for pPage */ const int hdr = pPage->hdrOffset; /* Offset of header on pPage */ const int nUsable = pPage->pBt->usableSize; /* Usable size of page */ assert( pPage->nOverflow==0 ); assert( sqlite3_mutex_held(pPage->pBt->mutex) ); assert( nCell>=0 && nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=5460 ); assert( sqlite3PagerIswriteable(pPage->pDbPage) ); /* Check that the page has just been zeroed by zeroPage() */ assert( pPage->nCell==0 ); assert( get2byte(&data[hdr+5])==nUsable ); pCellptr = &data[pPage->cellOffset + nCell*2]; cellbody = nUsable; for(i=nCell-1; i>=0; i--){ pCellptr -= 2; cellbody -= aSize[i]; put2byte(pCellptr, cellbody); memcpy(&data[cellbody], apCell[i], aSize[i]); } put2byte(&data[hdr+3], nCell); put2byte(&data[hdr+5], cellbody); pPage->nFree -= (nCell*2 + nUsable - cellbody); pPage->nCell = (u16)nCell; } /* ** The following parameters determine how many adjacent pages get involved ** in a balancing operation. NN is the number of neighbors on either side ** of the page that participate in the balancing operation. NB is the |
︙ | ︙ |