aboutsummaryrefslogtreecommitdiff
path: root/core/strings
diff options
context:
space:
mode:
authorKarl Zylinski <karl@zylinski.se>2024-06-29 08:23:39 +0200
committerKarl Zylinski <karl@zylinski.se>2024-06-29 08:57:21 +0200
commit679f9b4e413fb1cd9aad953cc7a7a287f5abf226 (patch)
treee96ec7d669312c1d9a280e9a8d35b983562daabb /core/strings
parent06652bebce111640930a513c825e59f7b37bbd4f (diff)
Made default capacity of dynamic arrays more consistent.
Before this if you do `arr: [dynamic]int` and then append to arr, then it will have capacity 8. But if you did `arr := make([dynamic]int, context.temp_allocator)` then arr would have capacity 16. Now both `arr: [dynamic]int` and `arr := make([dynamic]int, context.temp_allocator)` will resut in arr having zero 0. The only reason to use `make` without an explicit len or cap now is because you want to set it up for a non-default allocator. After the first call to `append` it will now in both cases have capacity 8. I also updated the documentation on the strings builder, both to reflect this, and also to fix it incorrectly saying that len would be 'max(16,len)', which wasn't true even before these changes.
Diffstat (limited to 'core/strings')
-rw-r--r--core/strings/builder.odin12
1 files changed, 6 insertions, 6 deletions
diff --git a/core/strings/builder.odin b/core/strings/builder.odin
index 33054a8a9..6bb0b2018 100644
--- a/core/strings/builder.odin
+++ b/core/strings/builder.odin
@@ -24,7 +24,7 @@ Builder :: struct {
buf: [dynamic]byte,
}
/*
-Produces a Builder with a default length of 0 and cap of 16
+Produces an empty Builder
*Allocates Using Provided Allocator*
@@ -39,7 +39,7 @@ builder_make_none :: proc(allocator := context.allocator, loc := #caller_locatio
return Builder{buf=make([dynamic]byte, allocator, loc) or_return }, nil
}
/*
-Produces a Builder with a specified length and cap of max(16,len) byte buffer
+Produces a Builder with specified length and capacity `len`.
*Allocates Using Provided Allocator*
@@ -55,7 +55,7 @@ builder_make_len :: proc(len: int, allocator := context.allocator, loc := #calle
return Builder{buf=make([dynamic]byte, len, allocator, loc) or_return }, nil
}
/*
-Produces a Builder with a specified length and cap
+Produces a Builder with specified length `len` and capacity `cap`.
*Allocates Using Provided Allocator*
@@ -103,7 +103,7 @@ builder_make :: proc{
builder_make_len_cap,
}
/*
-Initializes a Builder with a length of 0 and cap of 16
+Initializes an empty Builder
It replaces the existing `buf`
*Allocates Using Provided Allocator*
@@ -121,7 +121,7 @@ builder_init_none :: proc(b: ^Builder, allocator := context.allocator, loc := #c
return b, nil
}
/*
-Initializes a Builder with a specified length and cap, which is max(len,16)
+Initializes a Builder with specified length and capacity `len`.
It replaces the existing `buf`
*Allocates Using Provided Allocator*
@@ -140,7 +140,7 @@ builder_init_len :: proc(b: ^Builder, len: int, allocator := context.allocator,
return b, nil
}
/*
-Initializes a Builder with a specified length and cap
+Initializes a Builder with specified length `len` and capacity `cap`.
It replaces the existing `buf`
Inputs: