mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
"none" keyword for optionals + more memory fixes
This commit is contained in:
@ -155,8 +155,7 @@ fn (m map) bs(query string, start, end int, out voidptr) {
|
||||
fn preorder_keys(node &mapnode, keys mut []string, key_i int) int {
|
||||
mut i := key_i
|
||||
if !node.is_empty {
|
||||
mut a := *keys
|
||||
a[i] = node.key
|
||||
keys[i] = node.key
|
||||
i++
|
||||
}
|
||||
if !isnil(node.left) {
|
||||
|
@ -5,21 +5,26 @@
|
||||
module builtin
|
||||
|
||||
struct Option {
|
||||
data [255]byte
|
||||
error string
|
||||
ok bool
|
||||
data [255]byte
|
||||
error string
|
||||
ok bool
|
||||
is_none bool
|
||||
}
|
||||
|
||||
// `fn foo() ?Foo { return foo }` => `fn foo() ?Foo { return opt_ok(foo); }`
|
||||
fn opt_ok(data voidptr, size int) Option {
|
||||
if size >= 255 {
|
||||
panic('option size too big: $size (max is 255), this is a temporary limit')
|
||||
}
|
||||
res := Option {
|
||||
panic('option size too big: $size (max is 255), this is a temporary limit')
|
||||
}
|
||||
res := Option {
|
||||
ok: true
|
||||
}
|
||||
C.memcpy(res.data, data, size)
|
||||
return res
|
||||
C.memcpy(res.data, data, size)
|
||||
return res
|
||||
}
|
||||
|
||||
fn opt_none() Option {
|
||||
return Option{ is_none: true }
|
||||
}
|
||||
|
||||
pub fn error(s string) Option {
|
||||
|
Reference in New Issue
Block a user