mirror of
https://github.com/vlang/v.git
synced 2025-09-15 15:32:27 +03:00
builtin: optimise the common case of s.contains("x")
add s.contains_byte(x)
(#17702)
This commit is contained in:
parent
14148f3e52
commit
3793bf1c99
2 changed files with 51 additions and 10 deletions
|
@ -1,5 +1,3 @@
|
|||
import strings
|
||||
|
||||
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
@ -1213,3 +1211,35 @@ fn test_indent_width() {
|
|||
assert '\t\tabc'.indent_width() == 2
|
||||
assert '\t\t abc'.indent_width() == 3
|
||||
}
|
||||
|
||||
fn test_index_u8() {
|
||||
assert 'abcabca'.index_u8(`a`) == 0
|
||||
assert 'abcabca'.index_u8(`b`) == 1
|
||||
assert 'abcabca'.index_u8(`c`) == 2
|
||||
//
|
||||
assert 'abc'.index_u8(`d`) == -1
|
||||
assert 'abc'.index_u8(`A`) == -1
|
||||
assert 'abc'.index_u8(`B`) == -1
|
||||
assert 'abc'.index_u8(`C`) == -1
|
||||
//
|
||||
}
|
||||
|
||||
fn test_last_index_u8() {
|
||||
assert 'abcabca'.last_index_u8(`a`) == 6
|
||||
assert 'abcabca'.last_index_u8(`c`) == 5
|
||||
assert 'abcabca'.last_index_u8(`b`) == 4
|
||||
assert 'Zabcabca'.last_index_u8(`Z`) == 0
|
||||
//
|
||||
assert 'abc'.index_u8(`d`) == -1
|
||||
assert 'abc'.index_u8(`A`) == -1
|
||||
assert 'abc'.index_u8(`B`) == -1
|
||||
assert 'abc'.index_u8(`C`) == -1
|
||||
}
|
||||
|
||||
fn test_contains_byte() {
|
||||
assert 'abc abca'.contains_u8(`a`)
|
||||
assert 'abc abca'.contains_u8(`b`)
|
||||
assert 'abc abca'.contains_u8(`c`)
|
||||
assert 'abc abca'.contains_u8(` `)
|
||||
assert !'abc abca'.contains_u8(`A`)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue