Browse Source

add 2 constructors in CDiskBlockPos to simplify class usage

- add a default-constructor, which simply calls SetNull() and a
  constructor to directly pass nFile and nPos
- change code to use that new constructors
0.8
Philip Kaufmann 12 years ago
parent
commit
a8a4b9673e
  1. 4
      src/init.cpp
  2. 4
      src/main.cpp
  3. 15
      src/main.h

4
src/init.cpp

@ -346,9 +346,7 @@ void ThreadImport(void *data) {
CImportingNow imp; CImportingNow imp;
int nFile = 0; int nFile = 0;
while (!fShutdown) { while (!fShutdown) {
CDiskBlockPos pos; CDiskBlockPos pos(nFile, 0);
pos.nFile = nFile;
pos.nPos = 0;
FILE *file = OpenBlockFile(pos, true); FILE *file = OpenBlockFile(pos, true);
if (!file) if (!file)
break; break;

4
src/main.cpp

@ -1535,9 +1535,7 @@ void static FlushBlockFile()
{ {
LOCK(cs_LastBlockFile); LOCK(cs_LastBlockFile);
CDiskBlockPos posOld; CDiskBlockPos posOld(nLastBlockFile, 0);
posOld.nFile = nLastBlockFile;
posOld.nPos = 0;
FILE *fileOld = OpenBlockFile(posOld); FILE *fileOld = OpenBlockFile(posOld);
FileCommit(fileOld); FileCommit(fileOld);

15
src/main.h

@ -192,6 +192,15 @@ public:
READWRITE(VARINT(nPos)); READWRITE(VARINT(nPos));
) )
CDiskBlockPos() {
SetNull();
}
CDiskBlockPos(int nFileIn, unsigned int nPosIn) {
nFile = nFileIn;
nPos = nPosIn;
}
friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b) { friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b) {
return (a.nFile == b.nFile && a.nPos == b.nPos); return (a.nFile == b.nFile && a.nPos == b.nPos);
} }
@ -1493,8 +1502,7 @@ public:
if (nStatus & BLOCK_HAVE_DATA) { if (nStatus & BLOCK_HAVE_DATA) {
ret.nFile = nFile; ret.nFile = nFile;
ret.nPos = nDataPos; ret.nPos = nDataPos;
} else }
ret.SetNull();
return ret; return ret;
} }
@ -1503,8 +1511,7 @@ public:
if (nStatus & BLOCK_HAVE_UNDO) { if (nStatus & BLOCK_HAVE_UNDO) {
ret.nFile = nFile; ret.nFile = nFile;
ret.nPos = nUndoPos; ret.nPos = nUndoPos;
} else }
ret.SetNull();
return ret; return ret;
} }

Loading…
Cancel
Save