Skip to content

Commit 1e28cea

Browse files
inline tiny func on httpcore (#15480)
1 parent f25ca0d commit 1e28cea

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

lib/pure/httpcore.nim

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ func toCaseInsensitive(headers: HttpHeaders, s: string): string {.inline.} =
113113
return if headers.isTitleCase: toTitleCase(s) else: toLowerAscii(s)
114114

115115
func newHttpHeaders*(titleCase=false): HttpHeaders =
116-
## Returns a new ``HttpHeaders`` object. if ``titleCase`` is set to true,
116+
## Returns a new ``HttpHeaders`` object. if ``titleCase`` is set to true,
117117
## headers are passed to the server in title case (e.g. "Content-Length")
118118
new result
119119
result.table = newTable[string, seq[string]]()
120120
result.isTitleCase = titleCase
121121

122122
func newHttpHeaders*(keyValuePairs:
123123
openArray[tuple[key: string, val: string]], titleCase=false): HttpHeaders =
124-
## Returns a new ``HttpHeaders`` object from an array. if ``titleCase`` is set to true,
124+
## Returns a new ``HttpHeaders`` object from an array. if ``titleCase`` is set to true,
125125
## headers are passed to the server in title case (e.g. "Content-Length")
126126
new result
127127
result.table = newTable[string, seq[string]]()
@@ -134,10 +134,10 @@ func newHttpHeaders*(keyValuePairs:
134134
result.table[key] = @[pair.val]
135135

136136

137-
func `$`*(headers: HttpHeaders): string =
138-
return $headers.table
137+
func `$`*(headers: HttpHeaders): string {.inline.} =
138+
$headers.table
139139

140-
proc clear*(headers: HttpHeaders) =
140+
proc clear*(headers: HttpHeaders) {.inline.} =
141141
headers.table.clear()
142142

143143
func `[]`*(headers: HttpHeaders, key: string): HttpHeaderValues =
@@ -206,7 +206,7 @@ func getOrDefault*(headers: HttpHeaders, key: string,
206206
else:
207207
return default
208208

209-
func len*(headers: HttpHeaders): int = return headers.table.len
209+
func len*(headers: HttpHeaders): int {.inline.} = headers.table.len
210210

211211
func parseList(line: string, list: var seq[string], start: int): int =
212212
var i = 0
@@ -323,21 +323,21 @@ proc `==`*(rawCode: string, code: HttpCode): bool
323323
## string form of itself.
324324
return cmpIgnoreCase(rawCode, $code) == 0
325325

326-
func is2xx*(code: HttpCode): bool =
326+
func is2xx*(code: HttpCode): bool {.inline.} =
327327
## Determines whether ``code`` is a 2xx HTTP status code.
328-
return code.int in {200 .. 299}
328+
code.int in {200 .. 299}
329329

330-
func is3xx*(code: HttpCode): bool =
330+
func is3xx*(code: HttpCode): bool {.inline.} =
331331
## Determines whether ``code`` is a 3xx HTTP status code.
332-
return code.int in {300 .. 399}
332+
code.int in {300 .. 399}
333333

334-
func is4xx*(code: HttpCode): bool =
334+
func is4xx*(code: HttpCode): bool {.inline.} =
335335
## Determines whether ``code`` is a 4xx HTTP status code.
336-
return code.int in {400 .. 499}
336+
code.int in {400 .. 499}
337337

338-
func is5xx*(code: HttpCode): bool =
338+
func is5xx*(code: HttpCode): bool {.inline.} =
339339
## Determines whether ``code`` is a 5xx HTTP status code.
340-
return code.int in {500 .. 599}
340+
code.int in {500 .. 599}
341341

342342
func `$`*(httpMethod: HttpMethod): string =
343343
return (system.`$`(httpMethod))[4 .. ^1].toUpperAscii()
@@ -366,5 +366,3 @@ when isMainModule:
366366
doAssert testTitleCase.hasKey("Content-Length")
367367
for key, val in testTitleCase:
368368
doAssert key == "Content-Length"
369-
370-

0 commit comments

Comments
 (0)