mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Str.reserve
This commit is contained in:
parent
f7b8094dfb
commit
ab721dd3c1
10 changed files with 32 additions and 0 deletions
|
@ -157,6 +157,7 @@ comptime {
|
|||
exportStrFn(str.strEqual, "equal");
|
||||
exportStrFn(str.substringUnsafe, "substring_unsafe");
|
||||
exportStrFn(str.getUnsafe, "get_unsafe");
|
||||
exportStrFn(str.reserve, "reserve");
|
||||
exportStrFn(str.strToUtf8C, "to_utf8");
|
||||
exportStrFn(str.fromUtf8C, "from_utf8");
|
||||
exportStrFn(str.fromUtf8RangeC, "from_utf8_range");
|
||||
|
|
|
@ -2446,3 +2446,11 @@ test "appendScalar: big 😀" {
|
|||
|
||||
try expect(actual.eq(expected));
|
||||
}
|
||||
|
||||
pub fn reserve(string: RocStr, capacity: usize) callconv(.C) RocStr {
|
||||
if (capacity > string.capacity()) {
|
||||
return string.reallocate(capacity);
|
||||
} else {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ interface Str
|
|||
splitFirst,
|
||||
splitLast,
|
||||
walkUtf8WithIndex,
|
||||
reserve
|
||||
]
|
||||
imports [Bool.{ Bool }, Result.{ Result }]
|
||||
|
||||
|
@ -341,3 +342,6 @@ walkUtf8WithIndexHelp = \string, state, step, index, length ->
|
|||
walkUtf8WithIndexHelp string newState step (index + 1) length
|
||||
else
|
||||
state
|
||||
|
||||
## Make sure at least some number of bytes fit in this string without reallocating
|
||||
reserve : Str, Nat -> Str
|
||||
|
|
|
@ -333,6 +333,7 @@ pub const STR_TRIM: &str = "roc_builtins.str.trim";
|
|||
pub const STR_TRIM_LEFT: &str = "roc_builtins.str.trim_left";
|
||||
pub const STR_TRIM_RIGHT: &str = "roc_builtins.str.trim_right";
|
||||
pub const STR_GET_UNSAFE: &str = "roc_builtins.str.get_unsafe";
|
||||
pub const STR_RESERVE: &str = "roc_builtins.str.reserve";
|
||||
|
||||
pub const DICT_HASH: &str = "roc_builtins.dict.hash";
|
||||
pub const DICT_HASH_STR: &str = "roc_builtins.dict.hash_str";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue