cache string.hash()
parent
2ab1ad8b30
commit
28843a12c7
|
@ -49,11 +49,6 @@ enum Pass {
|
||||||
main
|
main
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mykek(o OS) {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct V {
|
struct V {
|
||||||
mut:
|
mut:
|
||||||
os OS // the OS to build for
|
os OS // the OS to build for
|
||||||
|
|
|
@ -2301,7 +2301,7 @@ fn (p mut Parser) array_init() string {
|
||||||
name := p.check_name()
|
name := p.check_name()
|
||||||
if p.table.known_type(name) {
|
if p.table.known_type(name) {
|
||||||
p.cgen.cur_line = ''
|
p.cgen.cur_line = ''
|
||||||
p.gen('{} /* arkek init*/')
|
p.gen('{}')
|
||||||
return '[$lit]$name'
|
return '[$lit]$name'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -314,8 +314,8 @@ fn (s mut Scanner) scan() ScanRes {
|
||||||
case `$`:
|
case `$`:
|
||||||
return scan_res(.dollar, '')
|
return scan_res(.dollar, '')
|
||||||
case `}`:
|
case `}`:
|
||||||
// s = `hello $name kek`
|
// s = `hello $name !`
|
||||||
// s = `hello ${name} kek`
|
// s = `hello ${name} !`
|
||||||
if s.inside_string {
|
if s.inside_string {
|
||||||
s.pos++
|
s.pos++
|
||||||
// TODO UN.neEDED?
|
// TODO UN.neEDED?
|
||||||
|
|
|
@ -32,7 +32,7 @@ mut:
|
||||||
fields []Var
|
fields []Var
|
||||||
methods []Fn
|
methods []Fn
|
||||||
parent string
|
parent string
|
||||||
func Fn // For cat == FN (type kek fn())
|
func Fn // For cat == FN (type myfn fn())
|
||||||
is_c bool // C.FI.le
|
is_c bool // C.FI.le
|
||||||
is_interface bool
|
is_interface bool
|
||||||
is_enum bool
|
is_enum bool
|
||||||
|
|
|
@ -6,6 +6,8 @@ module builtin
|
||||||
|
|
||||||
// V strings are not null-terminated.
|
// V strings are not null-terminated.
|
||||||
struct string {
|
struct string {
|
||||||
|
mut:
|
||||||
|
hash_cache int
|
||||||
pub:
|
pub:
|
||||||
str byteptr
|
str byteptr
|
||||||
len int
|
len int
|
||||||
|
@ -797,13 +799,12 @@ pub fn (c byte) is_white() bool {
|
||||||
|
|
||||||
|
|
||||||
pub fn (s string) hash() int {
|
pub fn (s string) hash() int {
|
||||||
mut hash := int(0)
|
mut h := s.hash_cache
|
||||||
for i := 0; i < s.len; i++ {
|
if h == 0 && s.len > 0 {
|
||||||
// if key == 'Content-Type' {
|
for c in s {
|
||||||
// println('$i) $hash')
|
h = h * 31 + int(c)
|
||||||
// }
|
}
|
||||||
hash = hash * int(31) + int(s.str[i])
|
}
|
||||||
}
|
return h
|
||||||
return hash
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,12 +155,12 @@ fn test_replace() {
|
||||||
assert b==('hello world')
|
assert b==('hello world')
|
||||||
b = b.replace('h', 'H')
|
b = b.replace('h', 'H')
|
||||||
assert b==('Hello world')
|
assert b==('Hello world')
|
||||||
b = b.replace('kek', 'lul')
|
b = b.replace('foo', 'bar')
|
||||||
assert b==('Hello world')
|
assert b==('Hello world')
|
||||||
s := 'hey man how are you'
|
s := 'hey man how are you'
|
||||||
assert s.replace('man ', '') == 'hey how are you'
|
assert s.replace('man ', '') == 'hey how are you'
|
||||||
lol := 'lol lol lol'
|
lol := 'lol lol lol'
|
||||||
assert lol.replace('lol', 'kek') == 'kek kek kek'
|
assert lol.replace('lol', 'LOL') == 'LOL LOL LOL'
|
||||||
b = 'oneBtwoBBthree'
|
b = 'oneBtwoBBthree'
|
||||||
assert b.replace('B', '') == 'onetwothree'
|
assert b.replace('B', '') == 'onetwothree'
|
||||||
b = '**char'
|
b = '**char'
|
||||||
|
|
|
@ -54,7 +54,6 @@ pub fn init() {
|
||||||
|
|
||||||
struct Face {
|
struct Face {
|
||||||
cobj voidptr
|
cobj voidptr
|
||||||
kek int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Cfg {
|
struct Cfg {
|
||||||
|
@ -368,7 +367,6 @@ pub fn new_context_text(cfg Cfg, scale int) *GG {
|
||||||
mut chars := []gg.Character{}
|
mut chars := []gg.Character{}
|
||||||
f := Face {
|
f := Face {
|
||||||
cobj: 0
|
cobj: 0
|
||||||
kek: 0
|
|
||||||
}
|
}
|
||||||
# f.cobj = &face;
|
# f.cobj = &face;
|
||||||
// # for (GLubyte c = 0; c < 128; c++)
|
// # for (GLubyte c = 0; c < 128; c++)
|
||||||
|
|
Loading…
Reference in New Issue