mirror of
https://github.com/sqlite/sqlite.git
synced 2025-10-31 18:11:01 +03:00
Micro-optimizations and comment fixes on the mem5.c memory allocator module.
FossilOrigin-Name: 8bf5e056eb8beb6e0ed5874fb24d7fe9f0b66d2b
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Fix\sthe\sspellfix1_scriptcode()\sfunction\sto\signore\swhitespace\sand\spunctuation,\nand\sto\srecognize\shebrew\sand\sarabic\sscripts.
|
C Micro-optimizations\sand\scomment\sfixes\son\sthe\smem5.c\smemory\sallocator\smodule.
|
||||||
D 2015-12-17T14:18:21.904
|
D 2015-12-18T16:29:47.912
|
||||||
F Makefile.in 28bcd6149e050dff35d4dcfd97e890cd387a499d
|
F Makefile.in 28bcd6149e050dff35d4dcfd97e890cd387a499d
|
||||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||||
F Makefile.msc 5fff077fcc46de7714ed6eebb6159a4c00eab751
|
F Makefile.msc 5fff077fcc46de7714ed6eebb6159a4c00eab751
|
||||||
@@ -304,7 +304,7 @@ F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
|
|||||||
F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b
|
F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b
|
||||||
F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3
|
F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3
|
||||||
F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a
|
F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a
|
||||||
F src/mem5.c 5c267678ba9f745a2ee58102a9f482d64a58577a
|
F src/mem5.c 262055c242fa7db59c5f07ad77fdc4e97888c054
|
||||||
F src/memjournal.c 3eb2c0b51adbd869cb6a44780323f05fa904dc85
|
F src/memjournal.c 3eb2c0b51adbd869cb6a44780323f05fa904dc85
|
||||||
F src/msvc.h d9ba56c6851227ab44b3f228a35f3f5772296495
|
F src/msvc.h d9ba56c6851227ab44b3f228a35f3f5772296495
|
||||||
F src/mutex.c 8e45800ee78e0cd1f1f3fe8e398853307f4a085c
|
F src/mutex.c 8e45800ee78e0cd1f1f3fe8e398853307f4a085c
|
||||||
@@ -1405,7 +1405,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f
|
|||||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||||
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
|
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
|
||||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||||
P 85ebd46c701e0a094a4690cd8f1d0cbae9aa257c
|
P 7adfa4a5794e47f97491c08abeaaac90e826b331
|
||||||
R 70cdc580d7d9b92b032d33f5e0d50f2e
|
R 1b3cde8c2a6658c08ed08e4868245c5a
|
||||||
U drh
|
U drh
|
||||||
Z 6d4b5ed9cd1870281d7d851922f323d8
|
Z 526b8930cb4e95afc320a389b1027b99
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
7adfa4a5794e47f97491c08abeaaac90e826b331
|
8bf5e056eb8beb6e0ed5874fb24d7fe9f0b66d2b
|
||||||
29
src/mem5.c
29
src/mem5.c
@@ -25,7 +25,7 @@
|
|||||||
**
|
**
|
||||||
** This memory allocator uses the following algorithm:
|
** This memory allocator uses the following algorithm:
|
||||||
**
|
**
|
||||||
** 1. All memory allocations sizes are rounded up to a power of 2.
|
** 1. All memory allocation sizes are rounded up to a power of 2.
|
||||||
**
|
**
|
||||||
** 2. If two adjacent free blocks are the halves of a larger block,
|
** 2. If two adjacent free blocks are the halves of a larger block,
|
||||||
** then the two blocks are coalesced into the single larger block.
|
** then the two blocks are coalesced into the single larger block.
|
||||||
@@ -117,7 +117,7 @@ static SQLITE_WSD struct Mem5Global {
|
|||||||
/*
|
/*
|
||||||
** Lists of free blocks. aiFreelist[0] is a list of free blocks of
|
** Lists of free blocks. aiFreelist[0] is a list of free blocks of
|
||||||
** size mem5.szAtom. aiFreelist[1] holds blocks of size szAtom*2.
|
** size mem5.szAtom. aiFreelist[1] holds blocks of size szAtom*2.
|
||||||
** and so forth.
|
** aiFreelist[2] holds free blocks of size szAtom*4. And so forth.
|
||||||
*/
|
*/
|
||||||
int aiFreelist[LOGMAX+1];
|
int aiFreelist[LOGMAX+1];
|
||||||
|
|
||||||
@@ -183,9 +183,7 @@ static void memsys5Link(int i, int iLogsize){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** If the STATIC_MEM mutex is not already held, obtain it now. The mutex
|
** Obtain or release the mutex needed to access global data structures.
|
||||||
** will already be held (obtained by code in malloc.c) if
|
|
||||||
** sqlite3GlobalConfig.bMemStat is true.
|
|
||||||
*/
|
*/
|
||||||
static void memsys5Enter(void){
|
static void memsys5Enter(void){
|
||||||
sqlite3_mutex_enter(mem5.mutex);
|
sqlite3_mutex_enter(mem5.mutex);
|
||||||
@@ -195,9 +193,8 @@ static void memsys5Leave(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Return the size of an outstanding allocation, in bytes. The
|
** Return the size of an outstanding allocation, in bytes.
|
||||||
** size returned omits the 8-byte header overhead. This only
|
** This only works for chunks that are currently checked out.
|
||||||
** works for chunks that are currently checked out.
|
|
||||||
*/
|
*/
|
||||||
static int memsys5Size(void *p){
|
static int memsys5Size(void *p){
|
||||||
int iSize, i;
|
int iSize, i;
|
||||||
@@ -230,14 +227,10 @@ static void *memsys5MallocUnsafe(int nByte){
|
|||||||
/* Keep track of the maximum allocation request. Even unfulfilled
|
/* Keep track of the maximum allocation request. Even unfulfilled
|
||||||
** requests are counted */
|
** requests are counted */
|
||||||
if( (u32)nByte>mem5.maxRequest ){
|
if( (u32)nByte>mem5.maxRequest ){
|
||||||
mem5.maxRequest = nByte;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Abort if the requested allocation size is larger than the largest
|
/* Abort if the requested allocation size is larger than the largest
|
||||||
** power of two that we can represent using 32-bit signed integers.
|
** power of two that we can represent using 32-bit signed integers. */
|
||||||
*/
|
if( nByte > 0x40000000 ) return 0;
|
||||||
if( nByte > 0x40000000 ){
|
mem5.maxRequest = nByte;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Round nByte up to the next valid power of two */
|
/* Round nByte up to the next valid power of two */
|
||||||
@@ -398,13 +391,11 @@ static void *memsys5Realloc(void *pPrior, int nBytes){
|
|||||||
if( nBytes<=nOld ){
|
if( nBytes<=nOld ){
|
||||||
return pPrior;
|
return pPrior;
|
||||||
}
|
}
|
||||||
memsys5Enter();
|
p = memsys5Malloc(nBytes);
|
||||||
p = memsys5MallocUnsafe(nBytes);
|
|
||||||
if( p ){
|
if( p ){
|
||||||
memcpy(p, pPrior, nOld);
|
memcpy(p, pPrior, nOld);
|
||||||
memsys5FreeUnsafe(pPrior);
|
memsys5Free(pPrior);
|
||||||
}
|
}
|
||||||
memsys5Leave();
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user