From: drh Date: Tue, 10 Jan 2006 20:32:32 +0000 (+0000) Subject: Combine multiple small calls to sqlite3OsWrite into one larger call. (CVS 2910) X-Git-Tag: version-3.6.10~3257 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97b574848714faed837372c67274e4654d176da0;p=thirdparty%2Fsqlite.git Combine multiple small calls to sqlite3OsWrite into one larger call. (CVS 2910) FossilOrigin-Name: e6e6750c24dc8b87be96bdc0e93254d7f0700543 --- diff --git a/manifest b/manifest index 06e726519e..b4153d014d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\scomments\son\sthe\sserver\sand\sasynchronous\sI/O\sdemo\sprograms.\s(CVS\s2909) -D 2006-01-10T20:01:19 +C Combine\smultiple\ssmall\scalls\sto\ssqlite3OsWrite\sinto\sone\slarger\scall.\s(CVS\s2910) +D 2006-01-10T20:32:32 F Makefile.in ab3ffd8d469cef4477257169b82810030a6bb967 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -59,7 +59,7 @@ F src/os_unix.c 8943febbedc79649d21ec1ed14de14ad8214c899 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_win.c 8ef250a0965a55dbcd8ef785e03f9f3292e6ade2 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c f84488fa616f1279761aaf06b0acc42af345d3a5 +F src/pager.c 0a59a320b0da6b22d2dd4411d16e300ff1b947c8 F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f F src/parse.y 83df51fea35f68f7e07384d75dce83d1ed30434c F src/pragma.c 711992e440ce78569322dd625d2cfe1cd696ccfb @@ -340,7 +340,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 1cf6855430352ffbf921a977186345d7272fe272 -R c77d71bb3bbb59cc1b67cf59dbab5a91 +P c0f47ccbc915f20d56f393383c21b4026785e6a5 +R 47f576a3900e4c28937875b78f472e44 U drh -Z 85b6b185878e0427b46314ea83850303 +Z b4dc310261f3df513fff82ddf0ae5002 diff --git a/manifest.uuid b/manifest.uuid index b1df334272..55db504846 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c0f47ccbc915f20d56f393383c21b4026785e6a5 \ No newline at end of file +e6e6750c24dc8b87be96bdc0e93254d7f0700543 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 08582ef01f..a8d601e526 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.234 2006/01/09 23:40:25 drh Exp $ +** @(#) $Id: pager.c,v 1.235 2006/01/10 20:32:32 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -444,15 +444,22 @@ static int read32bits(OsFile *fd, u32 *pRes){ } /* -** Write a 32-bit integer into the given file descriptor. Return SQLITE_OK -** on success or an error code is something goes wrong. +** Write a 32-bit integer into a string buffer in big-endian byte order. */ -static int write32bits(OsFile *fd, u32 val){ - unsigned char ac[4]; +static void put32bits(char *ac, u32 val){ ac[0] = (val>>24) & 0xff; ac[1] = (val>>16) & 0xff; ac[2] = (val>>8) & 0xff; ac[3] = val & 0xff; +} + +/* +** Write a 32-bit integer into the given file descriptor. Return SQLITE_OK +** on success or an error code is something goes wrong. +*/ +static int write32bits(OsFile *fd, u32 val){ + unsigned char ac[4]; + put32bits(ac, val); return sqlite3OsWrite(fd, ac, 4); } @@ -463,10 +470,7 @@ static int write32bits(OsFile *fd, u32 val){ static void store32bits(u32 val, PgHdr *p, int offset){ unsigned char *ac; ac = &((unsigned char*)PGHDR_TO_DATA(p))[offset]; - ac[0] = (val>>24) & 0xff; - ac[1] = (val>>16) & 0xff; - ac[2] = (val>>8) & 0xff; - ac[3] = val & 0xff; + put32bits(ac, val); } /* @@ -656,6 +660,7 @@ static int seekJournalHdr(Pager *pPager){ ** Followed by (JOURNAL_HDR_SZ - 24) bytes of unused space. */ static int writeJournalHdr(Pager *pPager){ + char zHeader[sizeof(aJournalMagic)+16]; int rc = seekJournalHdr(pPager); if( rc ) return rc; @@ -674,25 +679,17 @@ static int writeJournalHdr(Pager *pPager){ ** Actually maybe the whole journal header should be delayed until that ** point. Think about this. */ - rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, sizeof(aJournalMagic)); - - if( rc==SQLITE_OK ){ - /* The nRec Field. 0xFFFFFFFF for no-sync journals. */ - rc = write32bits(pPager->jfd, pPager->noSync ? 0xffffffff : 0); - } - if( rc==SQLITE_OK ){ - /* The random check-hash initialiser */ - sqlite3Randomness(sizeof(pPager->cksumInit), &pPager->cksumInit); - rc = write32bits(pPager->jfd, pPager->cksumInit); - } - if( rc==SQLITE_OK ){ - /* The initial database size */ - rc = write32bits(pPager->jfd, pPager->dbSize); - } - if( rc==SQLITE_OK ){ - /* The assumed sector size for this process */ - rc = write32bits(pPager->jfd, pPager->sectorSize); - } + memcpy(zHeader, aJournalMagic, sizeof(aJournalMagic)); + /* The nRec Field. 0xFFFFFFFF for no-sync journals. */ + put32bits(&zHeader[sizeof(aJournalMagic)], pPager->noSync ? 0xffffffff : 0); + /* The random check-hash initialiser */ + sqlite3Randomness(sizeof(pPager->cksumInit), &pPager->cksumInit); + put32bits(&zHeader[sizeof(aJournalMagic)+4], pPager->cksumInit); + /* The initial database size */ + put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbSize); + /* The assumed sector size for this process */ + put32bits(&zHeader[sizeof(aJournalMagic)+12], pPager->sectorSize); + rc = sqlite3OsWrite(pPager->jfd, zHeader, sizeof(zHeader)); /* The journal header has been written successfully. Seek the journal ** file descriptor to the end of the journal header sector. @@ -792,7 +789,8 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){ int rc; int len; int i; - u32 cksum = 0; + u32 cksum = 0; + char zBuf[sizeof(aJournalMagic)+2*4]; if( !zMaster || pPager->setMaster) return SQLITE_OK; pPager->setMaster = 1; @@ -818,13 +816,10 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){ rc = sqlite3OsWrite(pPager->jfd, zMaster, len); if( rc!=SQLITE_OK ) return rc; - rc = write32bits(pPager->jfd, len); - if( rc!=SQLITE_OK ) return rc; - - rc = write32bits(pPager->jfd, cksum); - if( rc!=SQLITE_OK ) return rc; - - rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, sizeof(aJournalMagic)); + put32bits(zBuf, len); + put32bits(&zBuf[4], cksum); + memcpy(&zBuf[8], aJournalMagic, sizeof(aJournalMagic)); + rc = sqlite3OsWrite(pPager->jfd, zBuf, 8+sizeof(aJournalMagic)); pPager->needSync = !pPager->noSync; return rc; }