From 6998178d2db0e38dca2860887ade609637b05c8b Mon Sep 17 00:00:00 2001 From: Charles Blake Date: Wed, 29 Nov 2023 06:28:48 -0500 Subject: [PATCH 1/4] Silence several `Hint: passing 'EXPR' to a sink parameter introduces an implicit copy; if possible, rearrange your program's control flow to prevent it [Performance]` warnings that trigger without the `move`s. --- lib/pure/httpclient.nim | 2 +- lib/pure/httpcore.nim | 2 +- lib/pure/parsecfg.nim | 4 ++-- lib/std/cmdline.nim | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index fc66b96f522f5..08ea99627c1cf 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -1232,7 +1232,7 @@ proc responseContent(resp: Response | AsyncResponse): Future[string] {.multisync ## A `HttpRequestError` will be raised if the server responds with a ## client error (status code 4xx) or a server error (status code 5xx). if resp.code.is4xx or resp.code.is5xx: - raise newException(HttpRequestError, resp.status) + raise newException(HttpRequestError, resp.status.move) else: return await resp.bodyStream.readAll() diff --git a/lib/pure/httpcore.nim b/lib/pure/httpcore.nim index ab0c030a5c73e..85a8de1c9db43 100644 --- a/lib/pure/httpcore.nim +++ b/lib/pure/httpcore.nim @@ -164,7 +164,7 @@ func `[]`*(headers: HttpHeaders, key: string): HttpHeaderValues = ## To access multiple values of a key, use the overloaded `[]` below or ## to get all of them access the `table` field directly. {.cast(noSideEffect).}: - return headers.table[headers.toCaseInsensitive(key)].HttpHeaderValues + return headers.table[headers.toCaseInsensitive(key)].move.HttpHeaderValues converter toString*(values: HttpHeaderValues): string = return seq[string](values)[0] diff --git a/lib/pure/parsecfg.nim b/lib/pure/parsecfg.nim index ea9c183336654..8a43daf54fed5 100644 --- a/lib/pure/parsecfg.nim +++ b/lib/pure/parsecfg.nim @@ -452,7 +452,7 @@ proc getKeyValPair(c: var CfgParser, kind: CfgEventKind): CfgEvent = if c.tok.kind == tkSymbol: case kind of cfgOption, cfgKeyValuePair: - result = CfgEvent(kind: kind, key: c.tok.literal, value: "") + result = CfgEvent(kind: kind, key: c.tok.literal.move, value: "") else: discard rawGetTok(c, c.tok) if c.tok.kind in {tkEquals, tkColon}: @@ -481,7 +481,7 @@ proc next*(c: var CfgParser): CfgEvent {.rtl, extern: "npc$1".} = of tkBracketLe: rawGetTok(c, c.tok) if c.tok.kind == tkSymbol: - result = CfgEvent(kind: cfgSectionStart, section: c.tok.literal) + result = CfgEvent(kind: cfgSectionStart, section: c.tok.literal.move) else: result = CfgEvent(kind: cfgError, msg: errorStr(c, "symbol expected, but found: " & c.tok.literal)) diff --git a/lib/std/cmdline.nim b/lib/std/cmdline.nim index 29c357d9d0d78..a57fb76a4e0db 100644 --- a/lib/std/cmdline.nim +++ b/lib/std/cmdline.nim @@ -138,7 +138,7 @@ proc parseCmdLine*(c: string): seq[string] {. while i < c.len and c[i] > ' ': add(a, c[i]) inc(i) - add(result, a) + add(result, move a) when defined(nimdoc): # Common forward declaration docstring block for parameter retrieval procs. From ee3fb05353eb550a8d15d964dbfbbbba4da73f98 Mon Sep 17 00:00:00 2001 From: Charles Blake Date: Wed, 29 Nov 2023 08:09:18 -0500 Subject: [PATCH 2/4] Withdraw `HttpHeaderValues` `move` (breaks tests/stdlib/thttpcore.nim); Add one for `parseHeader` 's `parseList` instead. --- lib/pure/httpcore.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pure/httpcore.nim b/lib/pure/httpcore.nim index 85a8de1c9db43..c909919f7dd8d 100644 --- a/lib/pure/httpcore.nim +++ b/lib/pure/httpcore.nim @@ -164,7 +164,7 @@ func `[]`*(headers: HttpHeaders, key: string): HttpHeaderValues = ## To access multiple values of a key, use the overloaded `[]` below or ## to get all of them access the `table` field directly. {.cast(noSideEffect).}: - return headers.table[headers.toCaseInsensitive(key)].move.HttpHeaderValues + return headers.table[headers.toCaseInsensitive(key)].HttpHeaderValues converter toString*(values: HttpHeaderValues): string = return seq[string](values)[0] @@ -234,7 +234,7 @@ func parseList(line: string, list: var seq[string], start: int): int = while start+i < line.len and line[start + i] notin {'\c', '\l'}: i += line.skipWhitespace(start + i) i += line.parseUntil(current, {'\c', '\l', ','}, start + i) - list.add(current) + list.add(move current) if start+i < line.len and line[start + i] == ',': i.inc # Skip , current.setLen(0) From ab83b4109ae6e59bd69da36a766f9a9cc57526f4 Mon Sep 17 00:00:00 2001 From: Charles Blake Date: Wed, 29 Nov 2023 09:49:09 -0500 Subject: [PATCH 3/4] Address code review; `move` does `setLen(0)`; Also include a comment to that effect. --- lib/pure/httpcore.nim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/pure/httpcore.nim b/lib/pure/httpcore.nim index c909919f7dd8d..e3632ead62d68 100644 --- a/lib/pure/httpcore.nim +++ b/lib/pure/httpcore.nim @@ -234,10 +234,9 @@ func parseList(line: string, list: var seq[string], start: int): int = while start+i < line.len and line[start + i] notin {'\c', '\l'}: i += line.skipWhitespace(start + i) i += line.parseUntil(current, {'\c', '\l', ','}, start + i) - list.add(move current) + list.add(move current) # implicit .setLen(0) if start+i < line.len and line[start + i] == ',': i.inc # Skip , - current.setLen(0) func parseHeader*(line: string): tuple[key: string, value: seq[string]] = ## Parses a single raw header HTTP line into key value pairs. From e0c68f8be1acd5877ab98aa80cfdb2a7e3a21a3a Mon Sep 17 00:00:00 2001 From: Charles Blake Date: Wed, 29 Nov 2023 10:02:36 -0500 Subject: [PATCH 4/4] Be more specific setLen refers to `current` not `list`. --- lib/pure/httpcore.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/httpcore.nim b/lib/pure/httpcore.nim index e3632ead62d68..45365c185153b 100644 --- a/lib/pure/httpcore.nim +++ b/lib/pure/httpcore.nim @@ -234,7 +234,7 @@ func parseList(line: string, list: var seq[string], start: int): int = while start+i < line.len and line[start + i] notin {'\c', '\l'}: i += line.skipWhitespace(start + i) i += line.parseUntil(current, {'\c', '\l', ','}, start + i) - list.add(move current) # implicit .setLen(0) + list.add(move current) # implicit current.setLen(0) if start+i < line.len and line[start + i] == ',': i.inc # Skip ,