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
#include <StackOrHeapArray.h>
#include "Journal.h"
#include "Debug.h"
@@ -799,8 +801,8 @@ Journal::_WriteTransactionToLog()
int32 maxVecs = runArrays.MaxArrayLength() + 1;
// one extra for the index block
iovec* vecs = (iovec*)malloc(sizeof(iovec) * maxVecs);
if (vecs == NULL) {
BStackOrHeapArray<iovec, 8> vecs(maxVecs);
if (!vecs.IsValid()) {
// TODO: write back log entries directly?
return B_NO_MEMORY;
}
@@ -836,10 +838,8 @@ Journal::_WriteTransactionToLog()
// make blocks available in the cache
const void* data = block_cache_get(fVolume->BlockCache(),
blockNumber + j);
if (data == NULL) {
free(vecs);
if (data == NULL)
return B_IO_ERROR;
}
add_to_iovec(vecs, index, maxVecs, data, fVolume->BlockSize());
count++;
@@ -867,8 +867,6 @@ Journal::_WriteTransactionToLog()
logStart = logPosition % fLogSize;
}
free(vecs);
LogEntry* logEntry = new(std::nothrow) LogEntry(this, fVolume->LogEnd(),
runArrays.LogEntryLength());
if (logEntry == NULL) {