aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
AgeCommit message (Collapse)Author
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
2022-01-27Set len on copied items arrayJohn Schmidt
Also fix the argument order for `expectEquals`.
2022-01-27Add ArrayList.cloneJohn Schmidt
This is a common operation and matches the API on other stdlib collections like HashMap and MultiArrayList.
2021-11-30allocgate: renamed getAllocator function to allocatorLee Cannon
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-11-01std.ArrayList: add ensureTotalCapacityPrecise and update doc commentsRyan Liptak
initCapacity did and still does use the ensureTotalCapacityPrecise logic because the initial capacity of an ArrayList is not important in terms of how it grows, so allocating a more exact slice up-front allows for saving memory when the array list never exceeds that initial allocation size. There are use cases where this precise capacity is useful outside of the `init` function, though, like in instances where the user does not call the `init` function themselves but otherwise knows that an ArrayList is empty so calling `ensureTotalCapacityPrecise` can give the same memory savings that `initCapacity` would have. Closes #9775
2021-10-28std.ArrayListUnmanaged: implement writer()Andrew Kelley
2021-09-12std: publicize ArrayListUnmanaged.allocatedSlice to match ArrayListSilver
2021-09-01std.os.windows: reorg to avoid `usingnamespace`Andrew Kelley
Down to 19 uses of `usingnamespace`.
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-07-28std/ArrayList: Allow `ArrayList(u0)` to be createdZach Banks
Enable creating ArrayList with zero-sized types. This type still tracks length, but does not allocate additional memory.
2021-07-20std.ArrayList: add missing assertion in appendSliceAssumeCapacityAndrew Kelley
2021-05-08Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
Conflicts: * doc/langref.html.in * lib/std/enums.zig * lib/std/fmt.zig * lib/std/hash/auto_hash.zig * lib/std/math.zig * lib/std/mem.zig * lib/std/meta.zig * test/behavior/alignof.zig * test/behavior/bitcast.zig * test/behavior/bugs/1421.zig * test/behavior/cast.zig * test/behavior/ptrcast.zig * test/behavior/type_info.zig * test/behavior/vector.zig Master branch added `try` to a bunch of testing function calls, and some lines also had changed how to refer to the native architecture and other `@import("builtin")` stuff.
2021-05-08std: update usage of std.testingVeikka Tuominen
2021-05-05std.ArrayList: add clearRetainingCapacity and clearAndFreeAndrew Kelley
2021-05-05Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
Conflicts: * build.zig * lib/std/array_list.zig * lib/std/c/ast.zig * lib/std/c/parse.zig * lib/std/os/bits/linux.zig
2021-05-04std: Accept unaligned slice in several ArrayListAligned opsLemonBoy
Do not impose the internal alignment requirements to the user-supplied parameters. Closes #8647
2021-04-16std: deprecate ensureCapacity, add two other capacity functionsAndrew Kelley
I've run into this footgun enough times, nearly every time I want `ensureUnusedCapacity`, not `ensureCapacity`. This commit deprecates `ensureCapacity` in favor of `ensureTotalCapacity` and introduces `ensureUnusedCapacity`.
2021-01-08Remove deprecated stream aliasesJay Petacat
2021-01-06Merge pull request #7622 from tetsuo-cpp/array-hash-map-improvementsAndrew Kelley
std: Support equivalent ArrayList operations in ArrayHashMap
2021-01-05stage2: rework the C backendAndrew Kelley
* std.ArrayList gains `moveToUnmanaged` and dead code `ArrayListUnmanaged.appendWrite` is deleted. * emit_h state is attached to Module rather than Compilation. * remove the implementation of emit-h because it did not properly integrate with incremental compilation. I will re-implement it in a follow-up commit. * Compilation: use the .codegen_failure tag rather than .dependency_failure tag for when `bin_file.updateDecl` fails. C backend: * Use a CValue tagged union instead of strings for C values. * Cleanly separate state into Object and DeclGen: - Object is present only when generating a .c file - DeclGen is present for both generating a .c and .h * Move some functions into their respective Object/DeclGen namespace. * Forward decls are managed by the incremental compilation frontend; C backend no longer renders function signatures based on callsites. For simplicity, all functions always get forward decls. * Constants are managed by the incremental compilation frontend. C backend no longer has a "constants" section. * Participate in incremental compilation. Each Decl gets an ArrayList for its generated C code and it is updated when the Decl is updated. During flush(), all these are joined together in the output file. * The new CValue tagged union is used to clean up using of assigning to locals without an additional pointer local. * Fix bug with bitcast of non-pointers making the memcpy destination immutable.
2021-01-06std: Rename ArrayList shrink => shrinkAndFreeAlex Cameron
2021-01-02Improve documentation for ArrayList, ArrayListUnmanaged, etc. (#7624)Cameron Conn
* Improve ArrayList & co documentation - Added doc comments about the validity of references to elements in an ArrayList and how they may become invalid after resizing operations. - This should help users avoid footguns in future. * Improve ArrayListUnmanaged & co's documentation - Port improved documentation from ArrayList and ArrayList aligned to their unmanaged counterparts. - Made documentation for ArrayListUnmanaged & co more inclusive and up-to-date. - Made documentation more consistent with `ArrayList`. * Corrections on ArrayList documentation. - Remove incorrect/unpreferred wording on ArrayList vs ArrayListUnmanaged. - Fix notes about the alignment of ArrayListAligned - Be more verbose with warnings on when pointers are invalidated. - Copy+paste a few warnings * add warning to replaceRange * revert changes to append documentation
2020-12-31Year++Frank Denis
2020-12-29std.ChildProcess: improvements to collectOutputPosixAndrew Kelley
* read directly into the ArrayList buffers. * respect max_output_bytes * std.ArrayList: - make `allocatedSlice` public. - add `unusedCapacitySlice`. I removed the Windows implementation of this stuff; I am doing a partial merge of LemonBoy's patch with the understanding that a later patch can add the Windows implementation after it is vetted.
2020-12-24std: clenup, fixes, fmtVeikka Tuominen
2020-12-23move ArrayListSentineled to std lib orphanageVeikka Tuominen
2020-11-07make ArrayList.span into a compile errorJosh Holland
2020-11-07remove deprecated uses of ArrayList.spanJosh Holland