mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
module cache fixes; do not allow function names starting with _
This commit is contained in:
@@ -29,7 +29,7 @@ fn new_array(mylen, cap, elm_size int) array {
|
||||
|
||||
|
||||
// TODO
|
||||
pub fn _make(len, cap, elm_size int) array {
|
||||
pub fn make(len, cap, elm_size int) array {
|
||||
return new_array(len, cap, elm_size)
|
||||
}
|
||||
|
||||
@@ -111,6 +111,13 @@ pub fn (a mut array) delete(idx int) {
|
||||
a.cap--
|
||||
}
|
||||
|
||||
fn (a array) get(i int) voidptr {
|
||||
if i < 0 || i >= a.len {
|
||||
panic('array index out of range: $i/$a.len')
|
||||
}
|
||||
return a.data + i * a.element_size
|
||||
}
|
||||
|
||||
fn (a array) _get(i int) voidptr {
|
||||
if i < 0 || i >= a.len {
|
||||
panic('array index out of range: $i/$a.len')
|
||||
@@ -175,6 +182,22 @@ fn (a mut array) set(idx int, val voidptr) {
|
||||
C.memcpy(a.data + a.element_size * idx, val, a.element_size)
|
||||
}
|
||||
|
||||
fn (arr mut array) push(val voidptr) {
|
||||
if arr.len >= arr.cap - 1 {
|
||||
cap := (arr.len + 1) * 2
|
||||
// println('_push: realloc, new cap=$cap')
|
||||
if arr.cap == 0 {
|
||||
arr.data = calloc(cap * arr.element_size)
|
||||
}
|
||||
else {
|
||||
arr.data = C.realloc(arr.data, cap * arr.element_size)
|
||||
}
|
||||
arr.cap = cap
|
||||
}
|
||||
C.memcpy(arr.data + arr.element_size * arr.len, val, arr.element_size)
|
||||
arr.len++
|
||||
}
|
||||
|
||||
fn (arr mut array) _push(val voidptr) {
|
||||
if arr.len >= arr.cap - 1 {
|
||||
cap := (arr.len + 1) * 2
|
||||
@@ -209,6 +232,24 @@ pub fn (arr mut array) _push_many(val voidptr, size int) {
|
||||
arr.len += size
|
||||
}
|
||||
|
||||
// `val` is array.data
|
||||
// TODO make private, right now it's used by strings.Builder
|
||||
pub fn (arr mut array) push_many(val voidptr, size int) {
|
||||
if arr.len >= arr.cap - size {
|
||||
cap := (arr.len + size) * 2
|
||||
// println('_push: realloc, new cap=$cap')
|
||||
if arr.cap == 0 {
|
||||
arr.data = calloc(cap * arr.element_size)
|
||||
}
|
||||
else {
|
||||
arr.data = C.realloc(arr.data, cap * arr.element_size)
|
||||
}
|
||||
arr.cap = cap
|
||||
}
|
||||
C.memcpy(arr.data + arr.element_size * arr.len, val, arr.element_size * size)
|
||||
arr.len += size
|
||||
}
|
||||
|
||||
pub fn (a array) reverse() array {
|
||||
arr := array {
|
||||
len: a.len
|
||||
@@ -291,7 +332,7 @@ pub fn (a mut []int) sort() {
|
||||
a.sort_with_compare(compare_ints)
|
||||
}
|
||||
|
||||
// Looking for an array index based on value.
|
||||
// Looking for an array index based on value.
|
||||
// If there is, it will return the index and if not, it will return `-1`
|
||||
// TODO: Implement for all types
|
||||
pub fn (a []string) index(v string) int {
|
||||
|
||||
@@ -57,7 +57,7 @@ pub fn print_backtrace(){
|
||||
}
|
||||
|
||||
// replaces panic when -debug arg is passed
|
||||
fn _panic_debug(line_no int, file, mod, fn_name, s string) {
|
||||
fn panic_debug(line_no int, file, mod, fn_name, s string) {
|
||||
println('================ V panic ================')
|
||||
println(' module: $mod')
|
||||
println(' function: ${fn_name}()')
|
||||
|
||||
@@ -47,7 +47,7 @@ fn new_hashmap(planned_nr_items int) hashmap {
|
||||
return hashmap{
|
||||
cap: cap
|
||||
elm_size: 4
|
||||
table: _make(cap, cap, sizeof(hashmapentry))
|
||||
table: make(cap, cap, sizeof(hashmapentry))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ pub fn _make(len, cap, elm_size int) array {
|
||||
|
||||
*/
|
||||
|
||||
pub fn _make(len, cap, elm_size int) array {
|
||||
pub fn make(len, cap, elm_size int) array {
|
||||
return array{}
|
||||
}
|
||||
|
||||
|
||||
@@ -125,6 +125,15 @@ fn (m mut map) _set(key string, val voidptr) {
|
||||
m.insert(mut m.root, key, val)
|
||||
}
|
||||
|
||||
fn (m mut map) set(key string, val voidptr) {
|
||||
if isnil(m.root) {
|
||||
m.root = new_node(key, val, m.element_size)
|
||||
m.size++
|
||||
return
|
||||
}
|
||||
m.insert(mut m.root, key, val)
|
||||
}
|
||||
|
||||
/*
|
||||
fn (m map) bs(query string, start, end int, out voidptr) {
|
||||
// println('bs "$query" $start -> $end')
|
||||
@@ -210,8 +219,8 @@ pub fn (m mut map) delete(key string) {
|
||||
m.size--
|
||||
}
|
||||
|
||||
pub fn (m map) exists(key string) {
|
||||
panic('map.exists(key) was removed from the language. Use `key in map` instead.')
|
||||
fn (m map) exists(key string) bool {
|
||||
return !isnil(m.root) && m.root.find2(key, m.element_size)
|
||||
}
|
||||
|
||||
fn (m map) _exists(key string) bool {
|
||||
|
||||
@@ -13,7 +13,7 @@ pub:
|
||||
|
||||
pub fn new_builder(initial_size int) Builder {
|
||||
return Builder {
|
||||
buf: _make(0, initial_size, sizeof(byte))
|
||||
buf: make(0, initial_size, sizeof(byte))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ pub:
|
||||
|
||||
pub fn new_builder(initial_size int) Builder {
|
||||
return Builder {
|
||||
buf: _make(0, initial_size, sizeof(byte))
|
||||
buf: make(0, initial_size, sizeof(byte))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
|
||||
module term
|
||||
|
||||
fn _format(msg, open, close string) string {
|
||||
pub fn format(msg, open, close string) string {
|
||||
return '\x1b[' + open + 'm' + msg + '\x1b[' + close + 'm'
|
||||
}
|
||||
|
||||
fn _format_rgb(r, g, b int, msg, open, close string) string {
|
||||
pub fn format_rgb(r, g, b int, msg, open, close string) string {
|
||||
return '\x1b[' + open + ';2;' + r.str() + ';' + g.str() + ';' + b.str() + 'm' + msg + '\x1b[' + close + 'm'
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,3 @@
|
||||
|
||||
module term
|
||||
|
||||
pub fn format(msg, open, close string) string {
|
||||
return _format(msg, open, close)
|
||||
}
|
||||
|
||||
pub fn format_rgb(r, g, b int, msg, open, close string) string {
|
||||
return _format_rgb(r, g, b, msg, open, close)
|
||||
}
|
||||
|
||||
@@ -4,10 +4,3 @@
|
||||
|
||||
module term
|
||||
|
||||
pub fn format(msg, open, close string) string {
|
||||
return _format(msg, open, close)
|
||||
}
|
||||
|
||||
pub fn format_rgb(r, g, b int, msg, open, close string) string {
|
||||
return _format_rgb(r, g, b, msg, open, close)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user