mirror of
https://github.com/vlang/v.git
synced 2025-09-14 15:02:33 +03:00
net,vweb: reduce allocations by ~80%
This commit is contained in:
parent
b3a9701129
commit
e7cad4f55d
12 changed files with 464 additions and 91 deletions
16
vlib/net/http/util.v
Normal file
16
vlib/net/http/util.v
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
module http
|
||||
|
||||
// A fast version that avoids allocations in s.split()
|
||||
// returns the locations of the 2 spaces
|
||||
// "GET / HTTP/1.1" => ["GET" "/" "HTTP/1.1"]
|
||||
fn fast_request_words(line string) (int, int) {
|
||||
space1 := line.index(' ') or { return 0, 0 }
|
||||
space2 := line.index_after(' ', space1 + 1)
|
||||
if space2 == -1 {
|
||||
return 0, 0
|
||||
}
|
||||
return space1, space2
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue