Skip to content
This repository was archived by the owner on May 14, 2022. It is now read-only.

Commit 892dba7

Browse files
committed
refactor compaction.js: avoid unnecessary function calls
1 parent bec87f2 commit 892dba7

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

compaction.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ function PersistentState(logFilename, blockSize) {
7878
if (stateFileExists(logFilename)) {
7979
raf.close(function onRAFClosed(err) {
8080
if (err) return cb(err)
81-
fs.unlink(raf.filename, function onStateFileDeleted(err) {
82-
if (err) return cb(err)
83-
else cb()
84-
})
81+
fs.unlink(raf.filename, cb)
8582
})
8683
} else {
8784
cb()
@@ -163,11 +160,9 @@ function Compaction(log, onDone) {
163160

164161
function savePersistentState(cb) {
165162
if (!unshiftedBlockBuf) {
166-
loadUnshiftedBlock(function onUnshiftedBlockLoaded() {
167-
saveIt.call(this)
168-
})
163+
loadUnshiftedBlock(saveIt)
169164
} else {
170-
saveIt.call(this)
165+
saveIt()
171166
}
172167

173168
function saveIt() {
@@ -249,9 +244,7 @@ function Compaction(log, onDone) {
249244
while (true) {
250245
// Fetch the unshifted block, if necessary
251246
if (!unshiftedBlockBuf) {
252-
loadUnshiftedBlock(function onUnshiftedBlockLoaded() {
253-
continueCompactingBlock()
254-
})
247+
loadUnshiftedBlock(continueCompactingBlock)
255248
return
256249
}
257250
// When all records have been shifted (thus end of log), stop compacting
@@ -273,7 +266,7 @@ function Compaction(log, onDone) {
273266
// Proceed to compact the next block if this block is full
274267
if (log.hasNoSpaceFor(unshiftedDataBuf, offsetInCompactedBlock)) {
275268
saveCompactedBlock()
276-
setImmediate(() => compactNextBlock())
269+
setImmediate(compactNextBlock)
277270
return
278271
}
279272

0 commit comments

Comments
 (0)