From 0bf9e7cb168654d583bd230391b5080d19c8f806 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 23 Nov 2019 12:58:06 -0500 Subject: [PATCH] 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. --- src/add-ons/kernel/file_systems/bfs/Journal.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Journal.cpp b/src/add-ons/kernel/file_systems/bfs/Journal.cpp index 5377f30ae1..f664a011f4 100644 --- a/src/add-ons/kernel/file_systems/bfs/Journal.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Journal.cpp @@ -7,6 +7,8 @@ //! Transaction and logging +#include + #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 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) {