aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
AgeCommit message (Collapse)Author
2025-10-11std.ArrayList: swapRemove set removed element to undefined (#25514)Fri3dNstuff
2025-09-20std: remove loop from growCapacityAndrew Kelley
I measured this against master branch and found no statistical difference. Since this code is simpler and logically superior due to always leaving sufficient unused capacity when growing, it is preferred over status quo.
2025-08-30upgrade more old API usesAndrew Kelley
2025-08-30rework std.Io.Writer.Allocating to support runtime-known alignmentAndrew Kelley
Also, breaking API changes to: * std.fs.Dir.readFileAlloc * std.fs.Dir.readFileAllocOptions
2025-08-29std.Io: delete GenericReaderAndrew Kelley
and delete deprecated alias std.io
2025-08-28std: delete most remaining uses of GenericWriterAndrew Kelley
2025-08-28std.Io: delete GenericWriterAndrew Kelley
2025-08-26`std.ArrayList`: add `insertSliceAssumeCapacity()` and ↵Rue
`insertSliceBounded()` (#24978) closes #24929
2025-08-15std.compress.zstd.Decompress fixesAndrew Kelley
* std.Io.Reader: appendRemaining no longer supports alignment and has different rules about how exceeding limit. Fixed bug where it would return success instead of error.StreamTooLong like it was supposed to. * std.Io.Reader: simplify appendRemaining and appendRemainingUnlimited to be implemented based on std.Io.Writer.Allocating * std.Io.Writer: introduce unreachableRebase * std.Io.Writer: remove minimum_unused_capacity from Allocating. maybe that flexibility could have been handy, but let's see if anyone actually needs it. The field is redundant with the superlinear growth of ArrayList capacity. * std.Io.Writer: growingRebase also ensures total capacity on the preserve parameter, making it no longer necessary to do ensureTotalCapacity at the usage site of decompression streams. * std.compress.flate.Decompress: fix rebase not taking into account seek * std.compress.zstd.Decompress: split into "direct" and "indirect" usage patterns depending on whether a buffer is provided to init, matching how flate works. Remove some overzealous asserts that prevented buffer expansion from within rebase implementation. * std.zig: fix readSourceFileToAlloc returning an overaligned slice which was difficult to free correctly. fixes #24608
2025-08-11std.ArrayList: make unmanaged the defaultAndrew Kelley
2025-08-11std: introduce orderedRemoveManyAndrew Kelley
This algorithm is non-trivial and makes sense for any data structure that acts as an array list, so I thought it would make sense as a method. I have a real world case for this in a music player application (deleting queue items). Adds the method to: * ArrayList * ArrayHashMap * MultiArrayList
2025-08-05std: remove BoundedArrayAndrew Kelley
This use case is handled by ArrayListUnmanaged via the "...Bounded" method variants, and it's more optimal to share machine code, versus generating multiple versions of each function for differing array lengths.
2025-08-05std.array_list: add bounded methodsAndrew Kelley
2025-08-05std: replace various mem copies with `@memmove`Andrew Kelley
2025-07-07std.io.Writer.Allocating: rename interface to writerAndrew Kelley
2025-07-07std.io: deprecated Reader/Writer; introduce new APIAndrew Kelley
2025-04-13std: eradicate u29 and embrace std.mem.AlignmentAndrew Kelley
2025-03-09std/containers: improve consistency using gpa parameter name for allocator.remeh
2025-02-26std.ArrayList: delete unit testAndrew Kelley
tests should use the API, not only verify compilation succeeds.
2025-02-13std.ArrayList: initial capacity based on cache line sizeAndrew Kelley
also std.MultiArrayList
2025-02-10std.ArrayList: popOrNull() -> pop() [v2] (#22720)Meghan Denny
2025-02-06std.mem.Allocator: introduce `remap` function to the interfaceAndrew Kelley
This one changes the size of an allocation, allowing it to be relocated. However, the implementation will still return `null` if it would be equivalent to new = alloc memcpy(new, old) free(old) Mainly this prepares for taking advantage of `mremap` which I thought would be a bigger deal but apparently is only available on Linux. Still, we should use it on Linux.
2025-01-15std.array_list: tiny refactor for pleasureAndrew Kelley
2024-10-31compiler: remove anonymous struct types, unify all tuplesmlugg
This commit reworks how anonymous struct literals and tuples work. Previously, an untyped anonymous struct literal (e.g. `const x = .{ .a = 123 }`) was given an "anonymous struct type", which is a special kind of struct which coerces using structural equivalence. This mechanism was a holdover from before we used RLS / result types as the primary mechanism of type inference. This commit changes the language so that the type assigned here is a "normal" struct type. It uses a form of equivalence based on the AST node and the type's structure, much like a reified (`@Type`) type. Additionally, tuples have been simplified. The distinction between "simple" and "complex" tuple types is eliminated. All tuples, even those explicitly declared using `struct { ... }` syntax, use structural equivalence, and do not undergo staged type resolution. Tuples are very restricted: they cannot have non-`auto` layouts, cannot have aligned fields, and cannot have default values with the exception of `comptime` fields. Tuples currently do not have optimized layout, but this can be changed in the future. This change simplifies the language, and fixes some problematic coercions through pointers which led to unintuitive behavior. Resolves: #16865
2024-09-12Replace deprecated default initializations with decl literalsLinus Groh
2024-09-01std: deprecate some incorrect default initializationsmlugg
In favour of newly-added decls, which can be used via decl literals.
2024-08-16Dwarf: rework self-hosted debug info from scratchJacob Young
This is in preparation for incremental and actually being able to debug executables built by the x86_64 backend.
2024-07-14std.ArrayList.unusedCapacitySlice: Return unaligned slice (#20490)gooncreeper
2024-07-09std: fix typos (#20560)Jora Troosh
2024-04-02Refactor ArrayList replaceRange testsMichael Lynch
2024-02-26Remove redundant test name prefixes now that test names are fully qualifiedRyan Liptak
Follow up to #19079, which made test names fully qualified. This fixes tests that now-redundant information in their test names. For example here's a fully qualified test name before the changes in this commit: "priority_queue.test.std.PriorityQueue: shrinkAndFree" and the same test's name after the changes in this commit: "priority_queue.test.shrinkAndFree"
2024-02-23std.ArrayList: fixedWriterAndrew Kelley
A writer that appends to the list, returning error.OutOfMemory rather than attempting to increase capacity.
2024-02-23std.ArrayList: add writerAssumeCapacityAndrew Kelley
Useful when you want to use an ArrayList to operate on a static buffer.
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.