aboutsummaryrefslogtreecommitdiff
path: root/lib/std/bounded_array.zig
AgeCommit message (Collapse)Author
2024-08-23Revert "Smaller memory footprint for BoundedArray (#16299)"Andrew Kelley
This reverts commit cb5a6be41ae0efc30d0b59a41b0763db966e5bf4. I deeply apologize for the churn. This change is problematic given that we do not have ranged integers (yet? see #3806). In the meantime, this type needs to be `usize`, matching the length and index types for all std lib data structures. Users who want to save memory should not use heap-allocated BoundedArray values, since it is inherently memory-inefficient. Use a different memory layout instead. If #3806 is accepted and implemented, the length value can become an integer with the appropriate range, without the footgun. If that proposal is not accepted, len type will remain a usize.
2024-08-17std.BoundedArray: add clear()mlugg
2024-05-21Implement addManyAsSlice for BoundedArraySimon Brown
2024-03-21std: promote tests to doctestsAndrew Kelley
Now these show up as "example usage" in generated documentation.
2023-07-03Smaller memory footprint for BoundedArray (#16299)John Simon
Store BoundedArray's length using the smallest possible integer Co-authored-by: zooster <r00ster91@proton.me>
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-05-07convert s[start..start+len] to s[start..][0..len]dweiller
2023-04-28update codebase to use `@memset` and `@memcpy`Andrew Kelley
2023-03-17add BoundedArrayAligned (#14580)Motiejus Jakštys
This is useful for creating byte buffers of actually-different-things. Copied the argument order from `Allocator.alignedAlloc` I noted that `ArrayListAligned` is going out of it's way to not set the alignment at comptime when it is not specified. However, I was not able to do that the same way here, and good people on IRC, @ifreund in particular (thanks!) assured me that [N]T align(@alignOf(T)) is equivalent to [N]T
2023-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2023-01-29std: restrict mem.span() and mem.len() to sentinel terminated pointersIsaac Freund
These functions are currently footgunny when working with pointers to arrays and slices. They just return the stated length of the array/slice without iterating and looking for the first sentinel, even if the array/slice is a sentinel terminated type. From looking at the quite small list of places in the standard library/compiler that this change breaks existing code, the new code looks to be more readable in all cases. The usage of std.mem.span/len was totally unneeded in most of the cases affected by this breaking change. We could remove these functions entirely in favor of other existing functions in std.mem such as std.mem.sliceTo(), but that would be a somewhat nasty breaking change as std.mem.span() is very widely used for converting sentinel terminated pointers to slices. It is however not at all widely used for anything else. Therefore I think it is better to break these few non-standard and potentially incorrect usages of these functions now and at some later time, if deemed worthwhile, finally remove these functions. If we wait for at least a full release cycle so that everyone adapts to this change first, updating for the removal could be a simple find and replace without needing to worry about the semantics.
2022-08-16AstGen: detect declarations shadowing localsVeikka Tuominen
Closes #9355
2022-08-08std: fix BoundedArray test checking wrong condition (#12372)Ryotaro "Justin" Kimura
2022-04-14std/bounded_array.zig: Add Writer interfaceAndrew Lee
2022-03-03std.BoundedArray: return explicit errors (#11044)Motiejus Jakštys
* std.BoundedArray: return explicit errors Makes it easier to mark explicit errors when using BoundedArray downstream. * std.BoundedArray.insert() returns Overflow only
2022-01-16Slice function of BoundedArray now returns slice based on self pointerJimmi Holst Christensen
If self pointer is const, the slice is const. Otherwise the slice is mutable.
2022-01-12Allow BoundArray to be default initializedJimmi Holst Christensen
2021-12-15std.bounded_array: support inserting a new value at the end (#10340)Arnav Singh
Since `BoundedArray.insert` internally reserves space for the element to be inserted, it can support inserting at the position that is the current length of the array. Change the check for the insertion position to allow this.
2021-11-20std.bounded_array: fix `self` parameter type in `constSlice`Rohlem
Because `.buffer` is an inline array field, we actually require `self` to be passed as a pointer. If the compiler decided to pass the object by copying, we would return a pointer to to-be-destroyed stack memory.
2021-11-14BoundedArray: add appendAssumeCapacityGregory Anders
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-08-24BoundedArray: a simple way to represent small data whose max size is known ↵Frank Denis
(#9134) This is a simple structure containing an array and a length, that can be viewed as a slice. It is useful to pass-by-copy small data whose exact size is known at runtime, but whose maximum size is known at comptime. This greatly simplifies code that otherwise would require an allocator, or reimplementing what this type does.