aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-05-11 18:08:37 +0200
committerbptato <nincsnevem662@gmail.com>2025-05-11 18:27:25 +0200
commite7a175c2878f0ae7edf1eca084edd9ff218a3aaf (patch)
tree965a6f74cdecc2864bc80e443acfb5d12bdc8e8c
parent07aa41a7c2cef7abb5abeec2dd8f6fdc0e8e3e47 (diff)
downloadchawan-e7a175c2878f0ae7edf1eca084edd9ff218a3aaf.tar.gz
Eliminate some superfluous copies
-rw-r--r--adapter/protocol/man.nim4
-rw-r--r--src/config/cookie.nim6
-rw-r--r--src/config/mailcap.nim4
-rw-r--r--src/css/cssparser.nim2
-rw-r--r--src/css/cssvalues.nim10
-rw-r--r--src/css/layout.nim2
-rw-r--r--src/css/selectorparser.nim2
-rw-r--r--src/html/dom.nim8
-rw-r--r--src/html/formdata.nim2
-rw-r--r--src/local/container.nim31
-rw-r--r--src/local/pager.nim8
-rw-r--r--src/server/buffer.nim2
-rw-r--r--src/server/loaderiface.nim2
-rw-r--r--src/types/color.nim2
-rw-r--r--src/types/path.nim2
-rw-r--r--src/utils/sandbox.nim2
-rw-r--r--src/utils/strwidth.nim2
-rw-r--r--src/utils/twtstr.nim14
18 files changed, 55 insertions, 50 deletions
diff --git a/adapter/protocol/man.nim b/adapter/protocol/man.nim
index d1566b87..4616f241 100644
--- a/adapter/protocol/man.nim
+++ b/adapter/protocol/man.nim
@@ -81,7 +81,7 @@ func processBackspace(line: string): string =
flushChar
if inU: s &= "</u>"
if inB: s &= "</b>"
- return s
+ move(s)
proc isCommand(paths: seq[string]; name, s: string): bool =
for p in paths:
@@ -109,7 +109,7 @@ proc readErrorMsg(efile: File; line: var string): string =
msg &= line
if not efile.readLine(line):
break
- return msg
+ move(msg)
proc processManpage(ofile, efile: File; header, keyword: string) =
var line = ""
diff --git a/src/config/cookie.nim b/src/config/cookie.nim
index 65731089..3fed3e5c 100644
--- a/src/config/cookie.nim
+++ b/src/config/cookie.nim
@@ -132,7 +132,7 @@ func defaultCookiePath(url: URL): string =
var path = url.pathname.untilLast('/')
if path == "" or path[0] != '/':
return "/"
- return move(path)
+ move(path)
func cookiePathMatches(cookiePath, requestPath: string): bool =
if requestPath.startsWith(cookiePath):
@@ -199,7 +199,7 @@ proc serialize*(cookieJar: CookieJar; url: URL): string =
res &= cookie.value
for j in countdown(expired.high, 0):
cookieJar.cookies.delete(expired[j])
- return move(res)
+ move(res)
proc parseSetCookie(str: string; t: int64; url: URL; persist: bool):
Opt[Cookie] =
@@ -285,7 +285,7 @@ proc nextField(state: var ParseState; iq: openArray[char]): string =
state.i += field.len
if state.i < iq.len and iq[state.i] == '\t':
inc state.i
- return move(field)
+ move(field)
proc nextBool(state: var ParseState; iq: openArray[char]): bool =
let field = state.nextField(iq)
diff --git a/src/config/mailcap.nim b/src/config/mailcap.nim
index 3e801734..0b879491 100644
--- a/src/config/mailcap.nim
+++ b/src/config/mailcap.nim
@@ -50,7 +50,7 @@ proc `$`*(entry: MailcapEntry): string =
if entry.test != "":
s &= ";test=" & entry.test
s &= '\n'
- return s
+ move(s)
proc has(state: MailcapParser; buf: openArray[char]): bool {.inline.} =
return state.at < buf.len
@@ -227,7 +227,7 @@ proc quoteFile*(file: string; qs: QuoteState): string =
elif qs == qsNormal:
s &= '\\'
s &= c
- return s
+ move(s)
proc unquoteCommand*(ecmd, contentType, outpath: string; url: URL;
canpipe: var bool; line = -1): string =
diff --git a/src/css/cssparser.nim b/src/css/cssparser.nim
index a1677b33..0da29036 100644
--- a/src/css/cssparser.nim
+++ b/src/css/cssparser.nim
@@ -239,7 +239,7 @@ proc consumeIdentSequence(iq: openArray[char]; n: var int): string =
else:
break
inc n
- return move(s)
+ move(s)
proc consumeNumber(iq: openArray[char]; n: var int):
tuple[isInt: bool; val: float32] =
diff --git a/src/css/cssvalues.nim b/src/css/cssvalues.nim
index 9e1340d4..111d4359 100644
--- a/src/css/cssvalues.nim
+++ b/src/css/cssvalues.nim
@@ -813,7 +813,7 @@ func numToBase(n: int; map: openArray[uint32]): string =
var res = ""
for i in countdown(tmp.high, 0):
res.addUTF8(tmp[i])
- return res
+ move(res)
func numToFixed(n: int32; map: openArray[uint32]): string =
if n in 1 .. map.len:
@@ -910,7 +910,7 @@ func japaneseNumber(i: int32; formal: bool): string =
n -= m
for j in countdown(ss.high, 0):
s &= $ss[j]
- return s
+ move(s)
func listMarker0(t: CSSListStyleType; i: int32): string =
return case t
@@ -1723,7 +1723,7 @@ func lengthShorthand(cvals: openArray[CSSComponentValue];
res.add(makeEntry(t, lengths[i]))
else:
return err()
- return ok(res)
+ return ok(move(res))
const PropertyMarginSpec = [
cptMarginTop, cptMarginRight, cptMarginBottom, cptMarginLeft
@@ -1881,8 +1881,8 @@ proc parseComputedValues*(name: string; value: seq[CSSComponentValue];
attrs: WindowAttributes): seq[CSSComputedEntry] =
var res: seq[CSSComputedEntry] = @[]
if res.parseComputedValues(name, value, attrs).isSome:
- return res
- return @[]
+ return move(res)
+ @[]
proc copyFrom*(a, b: CSSValues; t: CSSPropertyType) =
case t.reprType
diff --git a/src/css/layout.nim b/src/css/layout.nim
index 595637de..eb17e0da 100644
--- a/src/css/layout.nim
+++ b/src/css/layout.nim
@@ -2401,7 +2401,7 @@ proc calcUnspecifiedColIndices(tctx: var TableContext; W: var LUnit;
col.width *= specifiedRatio
col.reflow = true
W -= col.width
- return avail
+ move(avail)
func needsRedistribution(tctx: TableContext; computed: CSSValues): bool =
case tctx.space.w.t
diff --git a/src/css/selectorparser.nim b/src/css/selectorparser.nim
index 0492bb49..2ac028f6 100644
--- a/src/css/selectorparser.nim
+++ b/src/css/selectorparser.nim
@@ -530,7 +530,7 @@ proc parseSelectorList(cvals: seq[CSSComponentValue]; nested, forgiving: bool):
discard
else:
res.add(csel)
- return res
+ move(res)
proc parseSelectors*(cvals: seq[CSSComponentValue]): seq[ComplexSelector] =
return parseSelectorList(cvals, nested = false, forgiving = false)
diff --git a/src/html/dom.nim b/src/html/dom.nim
index c7142d21..f6211ae0 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -1569,7 +1569,7 @@ func `$`(tokenList: DOMTokenList): string {.jsfunc: "toString".} =
if i != 0:
s &= ' '
s &= $tok
- return move(s)
+ move(s)
proc update(tokenList: DOMTokenList) =
if not tokenList.element.attrb(tokenList.localName) and
@@ -2687,7 +2687,7 @@ func applyMediaQuery(ss: CSSStylesheet; window: Window): CSSStylesheet =
for mq in ss.mqList:
if mq.query.applies(window.settings.scripting, window.attrsp):
res.add(mq.children.applyMediaQuery(window))
- return move(res)
+ move(res)
proc applyUASheet*(document: Document) =
const ua = staticRead"res/ua.css"
@@ -3181,11 +3181,11 @@ proc setSelected*(option: HTMLOptionElement; selected: bool)
# <q>, <blockquote>
proc cite(this: HTMLQuoteElement): string {.jsfget.} =
- let s = this.attr(satCite)
+ var s = this.attr(satCite)
let url = parseURL(s, some(this.document.url))
if url.isSome:
return $url.get
- return s
+ move(s)
proc `cite=`(this: HTMLQuoteElement; s: sink string) {.jsfset: "cite".} =
this.attr(satCite, s)
diff --git a/src/html/formdata.nim b/src/html/formdata.nim
index 58ed4ede..095ec507 100644
--- a/src/html/formdata.nim
+++ b/src/html/formdata.nim
@@ -180,7 +180,7 @@ proc constructEntryList*(form: HTMLFormElement; submitter: Element = nil;
let dir = "ltr" #TODO bidi
entrylist.add((dirname, dir))
form.constructingEntryList = false
- return move(entrylist)
+ move(entrylist)
proc addFormDataModule*(ctx: JSContext) =
ctx.registerType(FormData)
diff --git a/src/local/container.nim b/src/local/container.nim
index f8cebbc2..96272921 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -272,13 +272,18 @@ proc clone*(container: Container; newurl: URL; loader: FileLoader):
func lineLoaded(container: Container; y: int): bool =
return y - container.lineshift in 0..container.lines.high
-func getLine(container: Container; y: int): SimpleFlexibleLine =
+func getLine(container: Container; y: int): lent SimpleFlexibleLine =
if container.lineLoaded(y):
return container.lines[y - container.lineshift]
- SimpleFlexibleLine()
+ {.cast(noSideEffect).}:
+ let line {.global.} = SimpleFlexibleLine()
+ return line
-iterator ilines*(container: Container; slice: Slice[int]): SimpleFlexibleLine
- {.inline.} =
+func getLineStr(container: Container; y: int): lent string =
+ return container.getLine(y).str
+
+iterator ilines(container: Container; slice: Slice[int]):
+ lent SimpleFlexibleLine {.inline.} =
for y in slice:
yield container.getLine(y)
@@ -306,8 +311,8 @@ func xend(container: Container): int {.inline.} =
func lastVisibleLine(container: Container): int =
min(container.fromy + container.height, container.numLines) - 1
-func currentLine(container: Container): string =
- return container.getLine(container.cursory).str
+func currentLine(container: Container): lent string =
+ return container.getLineStr(container.cursory)
func findColBytes(s: string; endx: int; startx = 0; starti = 0): int =
var w = startx
@@ -318,7 +323,7 @@ func findColBytes(s: string; endx: int; startx = 0; starti = 0): int =
return i
func cursorBytes(container: Container; y: int; cc = container.cursorx): int =
- return container.getLine(y).str.findColBytes(cc, 0, 0)
+ return container.getLineStr(y).findColBytes(cc, 0, 0)
func currentCursorBytes(container: Container; cc = container.cursorx): int =
return container.cursorBytes(container.cursory, cc)
@@ -380,8 +385,8 @@ func acursory*(container: Container): int =
func maxScreenWidth(container: Container): int =
result = 0
- for line in container.ilines(container.fromy..container.lastVisibleLine):
- result = max(line.str.width(), result)
+ for y in container.fromy..container.lastVisibleLine:
+ result = max(container.getLineStr(y).width(), result)
func getTitle*(container: Container): string {.jsfget: "title".} =
if container.title != "":
@@ -443,15 +448,15 @@ func colorNormal(container: Container; hl: Highlight; y: int;
let starty = hl.starty
let endy = hl.endy
if y in starty + 1 .. endy - 1:
- let w = container.getLine(y).str.width()
+ let w = container.getLineStr(y).width()
return min(limitx.a, w) .. min(limitx.b, w)
if y == starty and y == endy:
return max(hl.startx, limitx.a) .. min(hl.endx, limitx.b)
if y == starty:
- let w = container.getLine(y).str.width()
+ let w = container.getLineStr(y).width()
return max(hl.startx, limitx.a) .. min(limitx.b, w)
if y == endy:
- let w = container.getLine(y).str.width()
+ let w = container.getLineStr(y).width()
return min(limitx.a, w) .. min(hl.endx, limitx.b)
0 .. 0
@@ -472,7 +477,7 @@ func colorArea(container: Container; hl: Highlight; y: int;
return 0 .. 0
of stLine:
if y in hl.starty .. hl.endy:
- let w = container.getLine(y).str.width()
+ let w = container.getLineStr(y).width()
return min(limitx.a, w) .. min(limitx.b, w)
return 0 .. 0
else:
diff --git a/src/local/pager.nim b/src/local/pager.nim
index fd4d119c..4a38ac77 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -1026,7 +1026,7 @@ proc drawBufferAdvance(s: openArray[char]; bgcolor: CellColor; oi, ox: var int;
ls &= s[i]
oi = i
ox = x
- return move(ls)
+ move(ls)
proc drawBuffer(pager: Pager; container: Container; ofile: File): bool =
var format = Format()
@@ -1805,7 +1805,7 @@ proc getEditorCommand(pager: Pager; file: string; line = 1): string {.jsfunc.} =
if s[^1] != ' ':
s &= ' '
s &= quoteFile(file, qsNormal)
- return s
+ move(s)
proc openInEditor(pager: Pager; input: var string): bool =
try:
@@ -2032,7 +2032,7 @@ proc omniRewrite(pager: Pager; s: string): string =
var res: string
if ctx.fromJS(jsRet, res).isSome:
pager.lineHist[lmLocation].add(s)
- return res
+ return move(res)
pager.alert("Error in substitution of " & $rule.match & " for " & s &
": " & ctx.getExceptionMsg())
return s
@@ -2873,7 +2873,7 @@ proc askMailcapMsg(pager: Pager; shortContentType: string; i: int; sx: var int):
sx = px
break
msg = msg.substr(j)
- return msg
+ move(msg)
proc askMailcap(pager: Pager; container: Container; ostream: PosixStream;
contentType: string; i: int; response: Response; sx: int) =
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 622b1c30..9a23f826 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -850,7 +850,7 @@ proc updateHover*(buffer: Buffer; cursorx, cursory: int): UpdateHoverResult
if repaint:
buffer.maybeReshape()
buffer.prevHover = thisNode
- return move(hover)
+ move(hover)
proc loadResources(buffer: Buffer): EmptyPromise =
if buffer.window.pendingResources.len > 0:
diff --git a/src/server/loaderiface.nim b/src/server/loaderiface.nim
index aa4599a0..5ab88480 100644
--- a/src/server/loaderiface.nim
+++ b/src/server/loaderiface.nim
@@ -275,7 +275,7 @@ proc getCacheFile*(loader: FileLoader; cacheId, sourcePid: int): string =
var s: string
loader.withPacketReader r:
r.sread(s)
- return s
+ move(s)
proc redirectToFile*(loader: FileLoader; outputId: int; targetPath: string;
displayUrl: URL): bool =
diff --git a/src/types/color.nim b/src/types/color.nim
index cea37750..729bb196 100644
--- a/src/types/color.nim
+++ b/src/types/color.nim
@@ -293,7 +293,7 @@ func serialize*(c: ARGBColor): string =
res.pushHex(c.r)
res.pushHex(c.g)
res.pushHex(c.b)
- return res
+ return move(res)
let a = float64(c.a) / 255
return "rgba(" & $c.r & ", " & $c.g & ", " & $c.b & ", " & $a & ")"
diff --git a/src/types/path.nim b/src/types/path.nim
index 966eeb32..53332dc3 100644
--- a/src/types/path.nim
+++ b/src/types/path.nim
@@ -345,7 +345,7 @@ proc getLines*(path: Path): seq[Line] =
assert subpath.points.len == subpath.segments.len + 1
for i in 0 ..< subpath.segments.len:
lines.addLines(subpath, i)
- return lines
+ move(lines)
proc getLineSegments*(path: Path): PathLines =
if path.subpaths.len == 0:
diff --git a/src/utils/sandbox.nim b/src/utils/sandbox.nim
index 55cdedd6..38c294e4 100644
--- a/src/utils/sandbox.nim
+++ b/src/utils/sandbox.nim
@@ -79,7 +79,7 @@ elif SandboxMode == stSeccomp:
var s = currentSourcePath()
while s.len > 0 and s[^1] != '/':
s.setLen(s.len - 1)
- return s
+ move(s)
{.passl: sourceParent() & "../../lib/chaseccomp/chaseccomp.o".}
proc cha_enter_buffer_sandbox(): cint {.importc, cdecl.}
diff --git a/src/utils/strwidth.nim b/src/utils/strwidth.nim
index ea26c852..f302e20e 100644
--- a/src/utils/strwidth.nim
+++ b/src/utils/strwidth.nim
@@ -102,4 +102,4 @@ func expandPUATabsHard*(s: openArray[char]): string =
else:
for j in pi ..< i:
res &= s[j]
- return res
+ move(res)
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 908c13ea..97c73756 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -201,7 +201,7 @@ func toHexLower*(u: uint16): string =
for i in countdown(len - 1, 0):
s[i] = HexCharsLower[x and 0xF]
x = x shr 4
- return move(s)
+ move(s)
func controlToVisual*(u: uint32): string =
if u <= 0x1F:
@@ -211,7 +211,7 @@ func controlToVisual*(u: uint32): string =
var res = "["
res.pushHex(uint8(u))
res &= ']'
- return move(res)
+ move(res)
proc add*(s: var string; u: uint8) =
s.addInt(uint64(u))
@@ -257,7 +257,7 @@ func stripAndCollapse*(s: openArray[char]): string =
res &= ' '
res &= c
space = cspace
- return move(res)
+ move(res)
func until*(s: openArray[char]; c: set[char]; starti = 0): string =
result = ""
@@ -732,7 +732,7 @@ proc mimeQuote*(value: string): string =
if not found:
return value
s &= '"'
- return move(s)
+ move(s)
proc setContentTypeAttr*(contentType: var string; attrname, value: string) =
var i = contentType.find(';')
@@ -861,15 +861,15 @@ func btoa*(data: openArray[uint8]): string =
L += 3 - rem
var s = newStringOfCap(L)
s.btoa(data)
- return move(s)
+ move(s)
func btoa*(data: openArray[char]): string =
return btoa(data.toOpenArrayByte(0, data.len - 1))
proc getEnvEmpty*(name: string; fallback = ""): string =
- let res = getEnv(name, fallback)
+ var res = getEnv(name, fallback)
if res != "":
- return res
+ return move(res)
return fallback
iterator mypairs*[T](a: openArray[T]): tuple[key: int; val: lent T] {.inline.} =