async flush() {
// hold mutex whilst calling this function
- let ptr = this.eof
- for (let i = 0; i < this.write_list.length; ++i) {
- let buffer = this.write_list[i]
- let len = buffer.length
- assert(
- (await this.log.write(buffer, 0, len, ptr)).bytesWritten === len
- )
-
- // each block in write list is also pinned in read cache, unpin
- // (if not in read cache then it's special root entry with < >)
+ let ptr = this.eof, len = 0, i = 0, j = 0
+ for (; j < this.write_list.length; ++j) {
+ if (len >= 0x1000) {
+ let buffer = Buffer.concat(this.write_list.slice(i, j))
+ assert(buffer.length === len)
+ assert(
+ (await this.log.write(buffer, 0, len, ptr)).bytesWritten === len
+ )
+
+ ptr += len
+ len = 0
+ i = j
+ }
+ len += this.write_list[j].length
+ }
+ let buffer = Buffer.concat(this.write_list.slice(i, j))
+ assert(buffer.length === len)
+ assert(
+ (await this.log.write(buffer, 0, len, ptr)).bytesWritten === len
+ )
+ ptr += len
+ assert(ptr === this.eof1)
+
+ // each block in write list is also pinned in read cache, unpin
+ // note: do this afterwards as needs to be on disk when unpinned
+ // note: special root entry is not in read cache and is ignored
+ /*let*/ ptr = this.eof
+ for (/*let*/ i = 0; i < this.write_list.length; ++i) {
if (Object.prototype.hasOwnProperty.call(this.read_cache, ptr)) {
let cached_value = this.read_cache[ptr]
--cached_value.refs
if (cached_value.stale_count === 0)
delete this.read_cache[ptr]
}
-
- ptr += len
+ ptr += this.write_list[i].length
}
assert(ptr === this.eof1)
- this.eof = ptr
+ this.eof = ptr
this.write_list = []
}