bfs: Use StackOrHeapArray in Journal::_WriteTransactionToLog().

The number of iovecs is usually < 8 (64 bytes), so this avoids
a lot of unnecessary heap traffic. Plus, we don't have to call
free() manually anymore.
This commit is contained in:
Augustin Cavalier
2019-11-23 12:58:06 -05:00
parent cb29eafe25
commit 0bf9e7cb16
@@ -7,6 +7,8 @@
//! Transaction and logging //! Transaction and logging
#include <StackOrHeapArray.h>
#include "Journal.h" #include "Journal.h"
#include "Debug.h" #include "Debug.h"
@@ -799,8 +801,8 @@ Journal::_WriteTransactionToLog()
int32 maxVecs = runArrays.MaxArrayLength() + 1; int32 maxVecs = runArrays.MaxArrayLength() + 1;
// one extra for the index block // one extra for the index block
iovec* vecs = (iovec*)malloc(sizeof(iovec) * maxVecs); BStackOrHeapArray<iovec, 8> vecs(maxVecs);
if (vecs == NULL) { if (!vecs.IsValid()) {
// TODO: write back log entries directly? // TODO: write back log entries directly?
return B_NO_MEMORY; return B_NO_MEMORY;
} }
@@ -836,10 +838,8 @@ Journal::_WriteTransactionToLog()
// make blocks available in the cache // make blocks available in the cache
const void* data = block_cache_get(fVolume->BlockCache(), const void* data = block_cache_get(fVolume->BlockCache(),
blockNumber + j); blockNumber + j);
if (data == NULL) { if (data == NULL)
free(vecs);
return B_IO_ERROR; return B_IO_ERROR;
}
add_to_iovec(vecs, index, maxVecs, data, fVolume->BlockSize()); add_to_iovec(vecs, index, maxVecs, data, fVolume->BlockSize());
count++; count++;
@@ -867,8 +867,6 @@ Journal::_WriteTransactionToLog()
logStart = logPosition % fLogSize; logStart = logPosition % fLogSize;
} }
free(vecs);
LogEntry* logEntry = new(std::nothrow) LogEntry(this, fVolume->LogEnd(), LogEntry* logEntry = new(std::nothrow) LogEntry(this, fVolume->LogEnd(),
runArrays.LogEntryLength()); runArrays.LogEntryLength());
if (logEntry == NULL) { if (logEntry == NULL) {