aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
AgeCommit message (Collapse)Author
2024-01-19std.ArrayList: pedantic fixups to previous commitAndrew Kelley
* fix and clarify incorrect doc comments * unify the pattern of calling unmanaged methods
2024-01-19std.ArrayList: add replaceRangeAssumeCapacity methodGordon Cassie
2024-01-19std.ArrayList.replaceRange: remove unneded overflow checksErik Arvstedt
The code asserted that the range to be replaced is within bounds of `self.items`. This is now reflected in the doc comment. The old, wrong doc comment was copied from the `insert*` fns. With this assertion holding true, `start + len` is always within the address space and `start + new_items.len` is, at this point, always strictly within bounds of `self.items`.
2024-01-19std.ArrayList: remove `+ 1` overflow checksErik Arvstedt
2024-01-15std.ArrayList: pedantic rewordings of documentation and unit testsAndrew Kelley
2024-01-15std.array_list: Document and reduce illegal behavior in ArrayListsnotcancername
2024-01-13std.ArrayList: Clarify that ensureTotalCapacity/ensureTotalCapacityPrecise ↵Ryan Liptak
will never shrink the array Closes #18499
2023-11-22std.ArrayList: add initBuffer to the unmanaged array listAndrew Kelley
This is useful when you want to have an array list backed by a fixed slice of memory and no Allocator will be used. It's an alternative to BoundedArray as you will see in the following commit.
2023-11-19lib: correct unnecessary uses of 'var'mlugg
2023-10-23x86_64: implement enough to pass unicode testsJacob Young
* implement vector comparison * implement reduce for bool vectors * fix `@memcpy` bug * enable passing std tests
2023-10-22Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""Jacob Young
This reverts commit 6f0198cadbe29294f2bf3153a27beebd64377566.
2023-10-22Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"Andrew Kelley
This reverts commit 0c99ba1eab63865592bb084feb271cd4e4b0357e, reversing changes made to 5f92b070bf284f1493b1b5d433dd3adde2f46727. This caused a CI failure when it landed in master branch due to a 128-bit `@byteSwap` in std.mem.
2023-10-21x86_64: disable failing tests, enable test-std testingJacob Young
2023-09-30Improve (Unmanaged)ArrayList.insertLucas Santos
(Unmanaged)ArrayList.insert has the same inefficiency as the old insertSlice. With the new addManyAt, the solution is trivial. Also improves the test "growing memory preserves contents". In the previous implementation, if any changes were made to the ArrayList memory growth policy (function growMemory), the list could end up with enough capacity to not trigger a memory growth, defeating the purpose of the test. The new implementation more robustly triggers a memory growth.
2023-09-29std.ArrayList: fixups for the previous commitAndrew Kelley
* Move `computeBetterCapacity` to the bottom so that `pub` stuff shows up first. * Rename `computeBetterCapacity` to `growCapacity`. Every function implicitly computes something; that word is always redundant in a function name. "better" is vague. Better in what way? Instead we describe what is actually happening. "grow". * Improve doc comments to be very explicit about when element pointers are invalidated or not. * Rename `addManyAtIndex` to `addManyAt`. The parameter is named `index`; that is enough. * Extract some duplicated code into `addManyAtAssumeCapacity` and make it `pub`. * Since I audited every line of code for correctness, I changed the style to my personal preference. * Avoid a redundant `@memset` to `undefined` - memory allocation does that already. * Fixed comment giving the wrong reason for not calling `ensureTotalCapacity`.
2023-09-29std.ArrayList: insertSlice avoids extra memcpyLucas Santos
Includes a more robust implementation of replaceRange, which updates the ArrayListUnmanaged if state changes in the managed part of the code before returning an error. Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2023-09-06std: enable FailingAllocator to fail on resizeGregory Anders
Now that allocator.resize() is allowed to fail, programs may wish to test code paths that handle resize() failure. The simplest way to do this now is to replace the vtable of the testing allocator with one that uses Allocator.noResize for the 'resize' function pointer. An alternative way to support this testing capability is to augment the FailingAllocator (which is already useful for testing allocation failure scenarios) to intentionally fail on calls to resize(). To do this, add a 'resize_fail_index' parameter to the FailingAllocator that causes resize() to fail after the given number of calls.
2023-07-16std: reword some commentsAndrew Kelley
2023-07-12docs: Fix outdated doc comments about allocating 'at least' the requested sizeRyan Liptak
The 'at least' behavior of the Allocator interface was removed in #13666, so anything that used reallocAtLeast or the .at_least Exact behavior could still have doc comments that reference no-longer-true behavior. Funnily enough, ArrayList is the only place that used this functionality (outside of allocator test cases), so its doc comments are the only things that need to be fixed. This was checked by resetting to deda6b514691c3a7ffc7931469886d0e7be2f67e and searching for all instances of `reallocAtLeast` and `.at_least` (one of which would need to be used to get the `.at_least` behavior)
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-06-10InternPool: port most of value tagsJacob Young
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-04-28std.ArrayList: mark the appendNTimes methods inlineAndrew Kelley
The previous commit introduced an optimization to the LLVM backend that makes `@memset` lower more optimally when the element is comptime-known and has a repeating byte pattern. By making these functions inline, if the element parameter is comptime-known at the callsite, it will be comptime-known in the `@memset` call, causing more use of the LLVM `memset` intrinsic rather than an inline for loop when using the LLVM backend. This affects, for example, std.crypto.argon2, which calls appendNTimesAssumeCapacity with a `[128]u64` as the element. This is now lowered with a single `memset` call.
2023-04-25x86_64 backend: support `@memset` with slicesAndrew Kelley
2023-04-25add behavior test for `@memset` on slicesAndrew Kelley
and avoid new language feature in std.ArrayList for now, until x86_64 self-hosted backend can implement it.
2023-04-25change semantics of `@memcpy` and `@memset`Andrew Kelley
Now they use slices or array pointers with any element type instead of requiring byte pointers. This is a breaking enhancement to the language. The safety check for overlapping pointers will be implemented in a future commit. closes #14040
2023-04-23Improvements to docs and textzooster
* docs(std.math): elaborate on difference between absCast and absInt * docs(std.rand.Random.weightedIndex): elaborate on likelihood I think this makes it easier to understand. * langref: add small reminder * docs(std.fs.path.extension): brevity * docs(std.bit_set.StaticBitSet): mention the specific types * std.debug.TTY: explain what purpose this struct serves This should also make it clearer that this struct is not supposed to provide unrelated terminal manipulation functionality such as setting the cursor position or something because terminals are complicated and we should keep this struct simple and focused on debugging. * langref(package listing): brevity * langref: explain what exactly `threadlocal` causes to happen * std.array_list: link between swapRemove and orderedRemove Maybe this can serve as a TLDR and make it easier to decide. * PrefetchOptions.locality: clarify docs that this is a range This confused me previously and I thought I can only use either 0 or 3. * fix typos and more * std.builtin.CallingConvention: document some CCs * langref: explain possibly cryptic names I think it helps knowing what exactly these acronyms (@clz and @ctz) and abbreviations (@popCount) mean. * variadic function error: add missing preposition * std.fmt.format docs: nicely hyphenate * help menu: say what to optimize for I think this is slightly more specific than just calling it "optimizations". These are speed optimizations. I used the word "performance" here.
2023-04-22doc: fix minor grammar issues-k
2023-03-12std: Add ArrayList.insertAssumeCapacity()Isaac Freund
Also test and document that inserting at list.items.len is allowed.
2023-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2023-02-04Allow const for ArrayList.getLast, fix #14522Nicolas Goy
2023-01-16Add fromOwnedSliceSentinel to ArrayList ArrayList and ArrayListUnmanaged, ↵Michael Bartnett
add fromOwnedSlice to ArrayListUnmanaged
2023-01-03Add the two functions 'getLast' and 'getLastOrNull' to ↵Chris Boesch
ArrayListAligned/ArrayListAlignedUnmanaged.
2022-12-29add tests for fixed stage1 bugsVeikka Tuominen
Closes #1957 Closes #1994 Closes #2140 Closes #2746 Closes #2802 Closes #2855 Closes #2895 Closes #2981 Closes #3054 Closes #3158 Closes #3234 Closes #3259 Closes #3371 Closes #3376 Closes #3387 Closes #3529 Closes #3653 Closes #3750 Closes #3778 Closes #3882 Closes #3915 Closes #3929 Closes #3961 Closes #3988 Closes #4123 Closes #7448
2022-12-15ArrayList.toOwnedSlice: Fix potential for leaks when using errdeferRyan Liptak
#13666 introduced a footgun when using `toOwnedSlice` with `errdefer array_list.deinit()`, since `toOwnedSlice` could retain capacity if `resize` failed, meaning it would leak without `deinit` being called. This meant that the only correct way to use `toOwnedSlice` was with `defer` instead of `errdefer` to ensure that the ArrayList would get cleaned up. Now, toOwnedSlice will now behave similarly to how it did before #13666, in that it will always clear the ArrayList's capacity if the resize/realloc succeeds. This also reverts commit 05890a12f532ba9d58904a14381ec174b9efe473, which was contingent on the modified toOwnedSlice behavior. Closes #13946
2022-12-11std: Update ArrayList documentationMikael Berthe
Calling `deinit` might still be required after using `toOwnedSlice` now.
2022-12-05Allow const ArrayLists to be clonedMartin Wickham
2022-11-30std.ArrayList: fix shrinkAndFreeAndrew Kelley
Fixes a regression introduced in e35f297aeb993ec956ae80379ddf7f86069e109b. Now there is test coverage for ArrayList.shrinkAndFree in the case when resizing fails.
2022-11-29std.mem.Allocator: allow shrink to failAndrew Kelley
closes #13535
2022-11-18std.array_list: add a comment on every methods invalidating pointers.remeh
While it is already mentioned on the `items` attributes of the structs, it is interesting to comment in every method potentially invalidating pointers to items that they may do so.
2022-09-16std: remove deprecated API for the upcoming releaseAndrew Kelley
See #3811
2022-09-14std.ArrayList.ensureTotalCapacity: optimize and fix integer overflowalichraghi
Fixes #12099
2022-08-10link.MachO: use accurate alignment attribute on pointersAndrew Kelley
Also adds a new method to ArrayList: appendUnalignedSlice
2022-03-11std.ArrayList: use variable for local mutable stateAndrew Kelley
stage1 has the wrong semantics here
2022-02-22[std.ArrayList] return explicit errorsMotiejus Jakštys
All errors from std.ArrayList are allocation errors. Mark them as such. This is helpful when one wants to obtain a function pointer.
2022-02-18ArrayList: add unusedCapacitySlice to the unmanaged APIAndrew Kelley
This function is super nice thank you whoever added it 👍
2022-01-27Preserve alignment when cloningJohn Schmidt
2022-01-27Implement clone with initCapacity and appendSliceAssumeCapacityJohn Schmidt
`ArrayList.ensureTotalCapacityPrecise` uses `Allocator.reallocAtLeast` under the hood, which can return more than `new_capacity` bytes if `alignment != @alignOf(T)`. This implementation of `clone` assures that the case of `ensureTotalCapacityPrecise` is handled correctly. Thanks @Vexu and @squeek502 for pointing this out.
2022-01-27Use expectEqualSlices instead of loopJohn Schmidt