Tweak the inlining of stream.write

This commit is contained in:
Zahary Karadjov 2020-05-05 19:23:28 +03:00
commit 0d90e444c2
No known key found for this signature in database
GPG key ID: C8936F8A3073D609

View file

@ -445,8 +445,7 @@ proc tryMovingToNextPage(c: var WriteCursor) =
# pre-allocated cursor span, which is considered a Defect (a range error) # pre-allocated cursor span, which is considered a Defect (a range error)
fsAssert false, "Attempt to write past the end of a cursor" fsAssert false, "Attempt to write past the end of a cursor"
template writeByteImpl(s: OutputStream, b: byte, awaiter, writeOp, drainOp: untyped) = template writeToNewSpanImpl(s: OutputStream, b: byte, awaiter, writeOp, drainOp: untyped) =
if atEnd(s.span):
# Unsafe memory outputs don't use pages at all, so if our cursor # Unsafe memory outputs don't use pages at all, so if our cursor
# reached here, this is a range violation defect: # reached here, this is a range violation defect:
fsAssert canExtendOutput(s) fsAssert canExtendOutput(s)
@ -474,8 +473,15 @@ proc write*(c: var WriteCursor, b: byte) =
writeByte(c.span, b) writeByte(c.span, b)
proc write*(s: OutputStream, b: byte) = proc writeToNewSpan(s: OutputStream, b: byte) =
writeByteImpl(s, b, noAwait, writeSync, drainAllBuffersSync) writeToNewSpanImpl(s, b, noAwait, writeSync, drainAllBuffersSync)
template write*(sp: OutputStream, b: byte) =
let s = sp
if hasRunway(s.span):
writeByte(s.span, b)
else:
writeToNewSpan(s, b)
proc write*(sp: AsyncOutputStream, b: byte) = proc write*(sp: AsyncOutputStream, b: byte) =
let s = OutputStream sp let s = OutputStream sp
@ -484,8 +490,11 @@ proc write*(sp: AsyncOutputStream, b: byte) =
writeByte(s.span, b) writeByte(s.span, b)
template writeAndWait*(sp: AsyncOutputStream, b: byte) = template writeAndWait*(sp: AsyncOutputStream, b: byte) =
let s = sp let s = OutputStream sp
writeByteImpl(s, b, fsAwait, writeAsync, drainAllBuffersAsync) if hasRunway(s.span):
writeByte(s.span, b)
else:
writeToNewSpanImpl(s, b, fsAwait, writeAsync, drainAllBuffersAsync)
template write*(s: AsyncOutputStream, x: char) = template write*(s: AsyncOutputStream, x: char) =
write s, byte(x) write s, byte(x)