mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
When possible, use memcpy() to and from the mapped region instead of xWrite() and xRead().
FossilOrigin-Name: f8ca5622d99bedca957caa9ad311d798f63b3ce9
This commit is contained in:
14
manifest
14
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Fix\sa\sdropped\serror\scode\sin\spager.c.
|
C When\spossible,\suse\smemcpy()\sto\sand\sfrom\sthe\smapped\sregion\sinstead\sof\sxWrite()\sand\sxRead().
|
||||||
D 2013-03-15T19:13:42.183
|
D 2013-03-16T20:19:21.766
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in 9a804abbd3cae82d196e4d33aba13239e32522a5
|
F Makefile.in 9a804abbd3cae82d196e4d33aba13239e32522a5
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -162,7 +162,7 @@ F src/os.h 027491c77d2404c0a678bb3fb06286f331eb9b57
|
|||||||
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
|
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
|
||||||
F src/os_unix.c 2a4cd96aabf413f39cf562baebb27aa9993f6f54
|
F src/os_unix.c 2a4cd96aabf413f39cf562baebb27aa9993f6f54
|
||||||
F src/os_win.c f7da4dc0a2545c0a430080380809946ae4d676d6
|
F src/os_win.c f7da4dc0a2545c0a430080380809946ae4d676d6
|
||||||
F src/pager.c bdbcfe676cda9295572e4ce95a3fae827082f9f0
|
F src/pager.c 495c5344392d5932ea5072f20bfbd8a58cf19d67
|
||||||
F src/pager.h 81ac95f4fcfe21981f495146f6d7f2fe51afd110
|
F src/pager.h 81ac95f4fcfe21981f495146f6d7f2fe51afd110
|
||||||
F src/parse.y 5d5e12772845805fdfeb889163516b84fbb9ae95
|
F src/parse.y 5d5e12772845805fdfeb889163516b84fbb9ae95
|
||||||
F src/pcache.c f8043b433a57aba85384a531e3937a804432a346
|
F src/pcache.c f8043b433a57aba85384a531e3937a804432a346
|
||||||
@@ -184,7 +184,7 @@ F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
|
|||||||
F src/status.c bedc37ec1a6bb9399944024d63f4c769971955a9
|
F src/status.c bedc37ec1a6bb9399944024d63f4c769971955a9
|
||||||
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
|
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
|
||||||
F src/tclsqlite.c 3213f3101e3b85f047d6e389da5a53d76d3d7540
|
F src/tclsqlite.c 3213f3101e3b85f047d6e389da5a53d76d3d7540
|
||||||
F src/test1.c ff3e68eedfbd858c9b89cf03e3db233cd29be1d0
|
F src/test1.c 3dac8d76be8852d65ff8b9ce4b50ed08b999ed59
|
||||||
F src/test2.c 4178056dd1e7d70f954ad8a1e3edb71a2a784daf
|
F src/test2.c 4178056dd1e7d70f954ad8a1e3edb71a2a784daf
|
||||||
F src/test3.c 3c3c2407fa6ec7a19e24ae23f7cb439d0275a60d
|
F src/test3.c 3c3c2407fa6ec7a19e24ae23f7cb439d0275a60d
|
||||||
F src/test4.c bf9fa9bece01de08e6f5e02314e4af5c13590dfa
|
F src/test4.c bf9fa9bece01de08e6f5e02314e4af5c13590dfa
|
||||||
@@ -1038,7 +1038,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
|
|||||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||||
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
|
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
|
||||||
P b387e2f9d24dccac1fd040e309f6fc7ec1cfffba
|
P 022fdc986b33701abfd39621072ac3d9f9f7d43e
|
||||||
R 53728d59c72e59e92889436c2f9b085b
|
R e9d1b00daf0ae79f0e154b8607fa8ad8
|
||||||
U dan
|
U dan
|
||||||
Z 3a434ac42175412fea267939fd915765
|
Z 82853c015b40f8bb1665068f9eea77d4
|
||||||
|
@@ -1 +1 @@
|
|||||||
022fdc986b33701abfd39621072ac3d9f9f7d43e
|
f8ca5622d99bedca957caa9ad311d798f63b3ce9
|
41
src/pager.c
41
src/pager.c
@@ -2865,9 +2865,13 @@ static int readDbPage(PgHdr *pPg){
|
|||||||
}
|
}
|
||||||
if( rc==SQLITE_OK && !isInWal ){
|
if( rc==SQLITE_OK && !isInWal ){
|
||||||
i64 iOffset = (pgno-1)*(i64)pPager->pageSize;
|
i64 iOffset = (pgno-1)*(i64)pPager->pageSize;
|
||||||
rc = sqlite3OsRead(pPager->fd, pPg->pData, pgsz, iOffset);
|
if( pPager->pMap && pPager->nMapValid>=iOffset+pPager->pageSize ){
|
||||||
if( rc==SQLITE_IOERR_SHORT_READ ){
|
memcpy(pPg->pData, &((u8 *)(pPager->pMap))[iOffset], pPager->pageSize);
|
||||||
rc = SQLITE_OK;
|
}else{
|
||||||
|
rc = sqlite3OsRead(pPager->fd, pPg->pData, pgsz, iOffset);
|
||||||
|
if( rc==SQLITE_IOERR_SHORT_READ ){
|
||||||
|
rc = SQLITE_OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3834,13 +3838,14 @@ static int pagerMap(Pager *pPager){
|
|||||||
assert( pPager->pMap==0 && pPager->nMap==0 );
|
assert( pPager->pMap==0 && pPager->nMap==0 );
|
||||||
|
|
||||||
rc = sqlite3OsFileSize(pPager->fd, &sz);
|
rc = sqlite3OsFileSize(pPager->fd, &sz);
|
||||||
|
sz = sz & ~(4096-1);
|
||||||
|
|
||||||
if( rc==SQLITE_OK && sz>0 ){
|
if( rc==SQLITE_OK && sz>0 ){
|
||||||
int fd;
|
int fd;
|
||||||
rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_GETFD, (void *)&fd);
|
rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_GETFD, (void *)&fd);
|
||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
void *pMap = mmap(0, sz, PROT_READ, MAP_SHARED, fd, 0);
|
void *pMap = mmap(0, sz, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
if( pMap==MAP_FAILED ){
|
if( pMap==MAP_FAILED ){
|
||||||
assert( 0 );
|
|
||||||
return SQLITE_IOERR;
|
return SQLITE_IOERR;
|
||||||
}
|
}
|
||||||
pPager->pMap = pMap;
|
pPager->pMap = pMap;
|
||||||
@@ -3851,6 +3856,22 @@ static int pagerMap(Pager *pPager){
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int pagerRemap(Pager *pPager, Pgno nPage){
|
||||||
|
i64 sz = (i64)nPage * pPager->pageSize;
|
||||||
|
sz = sz & ~(4096-1);
|
||||||
|
|
||||||
|
if( pPager->nMap!=sz ){
|
||||||
|
void *pMap = mremap(pPager->pMap, pPager->nMap, sz, MREMAP_MAYMOVE);
|
||||||
|
if( pMap==MAP_FAILED ){
|
||||||
|
return SQLITE_IOERR;
|
||||||
|
}
|
||||||
|
pPager->pMap = pMap;
|
||||||
|
pPager->nMapValid = pPager->nMap = sz;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SQLITE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static int pagerAcquireMapPage(Pager *pPager, Pgno pgno, PgHdr **ppPage){
|
static int pagerAcquireMapPage(Pager *pPager, Pgno pgno, PgHdr **ppPage){
|
||||||
int rc;
|
int rc;
|
||||||
*ppPage = 0;
|
*ppPage = 0;
|
||||||
@@ -4225,7 +4246,11 @@ static int pager_write_pagelist(Pager *pPager, PgHdr *pList){
|
|||||||
CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM, pData);
|
CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM, pData);
|
||||||
|
|
||||||
/* Write out the page data. */
|
/* Write out the page data. */
|
||||||
rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset);
|
if( pPager->nMapValid>=(offset+pPager->pageSize) ){
|
||||||
|
memcpy(&((u8 *)(pPager->pMap))[offset], pData, pPager->pageSize);
|
||||||
|
}else{
|
||||||
|
rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset);
|
||||||
|
}
|
||||||
|
|
||||||
/* If page 1 was just written, update Pager.dbFileVers to match
|
/* If page 1 was just written, update Pager.dbFileVers to match
|
||||||
** the value now stored in the database file. If writing this
|
** the value now stored in the database file. If writing this
|
||||||
@@ -5089,8 +5114,8 @@ int sqlite3PagerSharedLock(Pager *pPager){
|
|||||||
** to be the right size but is not actually valid. Avoid this
|
** to be the right size but is not actually valid. Avoid this
|
||||||
** possibility by unmapping the db here. */
|
** possibility by unmapping the db here. */
|
||||||
pagerUnmap(pPager);
|
pagerUnmap(pPager);
|
||||||
}else if( ((i64)nPage*pPager->pageSize)!=pPager->nMap ){
|
}else if( pPager->pMap ){
|
||||||
pagerUnmap(pPager);
|
pagerRemap(pPager, nPage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
src/test1.c
24
src/test1.c
@@ -5844,6 +5844,29 @@ static int test_test_control(
|
|||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
|
||||||
|
static int test_getrusage(
|
||||||
|
void * clientData,
|
||||||
|
Tcl_Interp *interp,
|
||||||
|
int objc,
|
||||||
|
Tcl_Obj *CONST objv[]
|
||||||
|
){
|
||||||
|
char buf[1024];
|
||||||
|
struct rusage r;
|
||||||
|
memset(&r, 0, sizeof(r));
|
||||||
|
getrusage(RUSAGE_SELF, &r);
|
||||||
|
|
||||||
|
sprintf(buf, "ru_utime=%d.%06d ru_stime=%d.%06d ru_minflt=%d ru_majflt=%d",
|
||||||
|
r.ru_utime.tv_sec, r.ru_utime.tv_usec,
|
||||||
|
r.ru_stime.tv_sec, r.ru_stime.tv_usec,
|
||||||
|
r.ru_minflt, r.ru_majflt
|
||||||
|
);
|
||||||
|
Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1));
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
#if SQLITE_OS_WIN
|
#if SQLITE_OS_WIN
|
||||||
/*
|
/*
|
||||||
** Information passed from the main thread into the windows file locker
|
** Information passed from the main thread into the windows file locker
|
||||||
@@ -6233,6 +6256,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
|||||||
{ "print_explain_query_plan", test_print_eqp, 0 },
|
{ "print_explain_query_plan", test_print_eqp, 0 },
|
||||||
#endif
|
#endif
|
||||||
{ "sqlite3_test_control", test_test_control },
|
{ "sqlite3_test_control", test_test_control },
|
||||||
|
{ "getrusage", test_getrusage },
|
||||||
};
|
};
|
||||||
static int bitmask_size = sizeof(Bitmask)*8;
|
static int bitmask_size = sizeof(Bitmask)*8;
|
||||||
int i;
|
int i;
|
||||||
|
Reference in New Issue
Block a user