Skip to content

Commit

Permalink
inline tiny func on httpcore (nim-lang#15480)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco authored and mildred committed Jan 11, 2021
1 parent d84be10 commit fb3497b
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions lib/pure/httpcore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ func toCaseInsensitive(headers: HttpHeaders, s: string): string {.inline.} =
return if headers.isTitleCase: toTitleCase(s) else: toLowerAscii(s)

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

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


func `$`*(headers: HttpHeaders): string =
return $headers.table
func `$`*(headers: HttpHeaders): string {.inline.} =
$headers.table

proc clear*(headers: HttpHeaders) =
proc clear*(headers: HttpHeaders) {.inline.} =
headers.table.clear()

func `[]`*(headers: HttpHeaders, key: string): HttpHeaderValues =
Expand Down Expand Up @@ -206,7 +206,7 @@ func getOrDefault*(headers: HttpHeaders, key: string,
else:
return default

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

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

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

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

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

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

func `$`*(httpMethod: HttpMethod): string =
return (system.`$`(httpMethod))[4 .. ^1].toUpperAscii()
Expand Down Expand Up @@ -366,5 +366,3 @@ when isMainModule:
doAssert testTitleCase.hasKey("Content-Length")
for key, val in testTitleCase:
doAssert key == "Content-Length"


0 comments on commit fb3497b

Please sign in to comment.