aboutsummaryrefslogtreecommitdiff
path: root/lib/std/mem.zig
AgeCommit message (Collapse)Author
2025-10-31std: Skip element comparisons if `mem.order` args point to same memoryJay Petacat
This optimization is used in `mem.eql`, but was missing from `order`, `orderZ`, and `ascii.orderIgnoreCase`.
2025-10-29std.mem: improve containsAtLeastScalar implementation and renameAndrew Kelley
2025-10-29Io.net: partial implementation of dns lookupAndrew Kelley
2025-10-07std.mem.countScalar: rework to benefit from simd (#25477)Henry John Kupty
`findScalarPos` might do repetitive work, even if using simd. For example, when searching the string `/abcde/fghijk/lm` for the character `/`, a 16-byte wide search would yield `1000001000000100` but would only count the first `1` and re-search the remaining of the string. When testing locally, the difference was quite significative: ``` count scalar 5737 iterations 522.83us per iterations 0 bytes per iteration worst: 2370us median: 512us stddev: 107.64us count v2 38333 iterations 78.03us per iterations 0 bytes per iteration worst: 713us median: 76us stddev: 10.62us count scalar v2 99565 iterations 29.80us per iterations 0 bytes per iteration worst: 41us median: 29us stddev: 1.04us ``` Note that `count v2` is a simpler string search, similar to the remaining version of the simd approach: ``` pub fn countV2(comptime T: type, haystack: []const T, needle: T) usize { const n = haystack.len; if (n < 1) return 0; var count: usize = 0; for (haystack[0..n]) |item| { count += @intFromBool(item == needle); } return count; } ``` Which implies the compiler yields some optimized code for a simpler loop that is more performant than the `findScalarPos`-based approach, hence the usage of iterative approach for the remaining of the haystack. Co-authored-by: StAlKeR7779 <stalkek7779@yandex.ru>
2025-10-03std.mem: Add `countScalar`Ryan Liptak
2025-09-25std.mem: add cutLast and cutScalarLastAndrew Kelley
2025-09-25std.mem: rename all "index of" functionsAndrew Kelley
Moving towards our function naming convention of having one word per concept and constructing function names out of concatenated concepts. In `std.mem` the concepts are: * "find" - return index of substring * "pos" - starting index parameter * "last" - search from the end * "linear" - simple for loop rather than fancy algo * "scalar" - substring is a single element
2025-09-25std.mem: add cut and cutScalar and example usageAndrew Kelley
2025-09-25std.mem: rename chomp to cutAndrew Kelley
2025-09-25std.mem: introduce chompPrefix and chompSuffixAndrew Kelley
2025-09-24optimize std.mem.swaprpkak
2025-09-18std.mem: work around LoongArch inline asm bug in doNotOptimizeAway()Alex Rønne Petersen
https://github.com/llvm/llvm-project/issues/159200
2025-09-17mem.replace: Document that input/output cannot overlapRyan Liptak
2025-09-07std.mem.indexOfSentinel: eliminate unnecessary `@ptrCast`Andrew Kelley
it was always unnecessary but now it's illegal
2025-09-06Document std.mem.* functions (#25168)Frank Denis
* Document std.mem.* functions Functions in std.mem are essential for virtually all applications, yet many of them lacked documentation. Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-08-11aarch64: implement more assembler instructionsJacob Young
2025-07-22aarch64: add new from scratch self-hosted backendJacob Young
2025-07-19std.mem: add byteSwapAllElementsAndrew Kelley
2025-07-16zig fmtAndrew Kelley
2025-07-11Remove numerous things deprecated during the 0.14 release cycleLinus Groh
Basically everything that has a direct replacement or no uses left. Notable omissions: - std.ArrayHashMap: Too much fallout, needs a separate cleanup. - std.debug.runtime_safety: Too much fallout. - std.heap.GeneralPurposeAllocator: Lots of references to it remain, not a simple find and replace as "debug allocator" is not equivalent to "general purpose allocator". - std.io.Reader: Is being reworked at the moment. - std.unicode.utf8Decode(): No replacement, needs a new API first. - Manifest backwards compat options: Removal would break test data used by TestFetchBuilder. - panic handler needs to be a namespace: Many tests still rely on it being a function, needs a separate cleanup.
2025-07-07std.mem.byteSwapAllFields: support slicesAndrew Kelley
2025-06-23std.mem.byteSwapAllFields: support untagged unionsAli Cheraghi
2025-06-16rename spirv backend nameAli Cheraghi
`stage2_spirv64` -> `stage2_spirv`
2025-05-20compiler: Scaffold stage2_powerpc backend.Alex Rønne Petersen
Nothing interesting here; literally just the bare minimum so I can work on this on and off in a branch without worrying about merge conflicts in the non-backend code.
2025-05-12Merge pull request #23700 from sorairolake/rename-trimsAlex Rønne Petersen
chore(std.mem): Rename `trimLeft` and `trimRight` to `trimStart` and `trimEnd`
2025-04-30test(std.mem): Remove `trimStart` and `trimEnd` from `test trim`Shun Sakai
2025-04-27chore(std.mem): Rename `trimLeft` and `trimRight`Shun Sakai
Rename `trimLeft` to `trimStart`, and `trimRight` to `trimEnd`. `trimLeft` and `trimRight` functions remain as deprecated aliases for these new names.
2025-04-26std: deprecate std.mem.copy{Forwards,Backwards}dweiller
2025-04-13std: eradicate u29 and embrace std.mem.AlignmentAndrew Kelley
2025-04-11std: Disable some vector-related tests for hexagon.Alex Rønne Petersen
See: * https://github.com/llvm/llvm-project/issues/118879 * https://github.com/llvm/llvm-project/issues/134659
2025-03-24std.mem.bytesAsSlice: fix to support zero-bytes sized typessamy007
also added a test for json parsing of zero sized type
2025-03-24fix: Allocator.remap now handles zero-bytes sized typessamy007
2025-02-25std.mem.indexOfSentinel: don't ask the OS the page sizeAndrew Kelley
simply use page_size_min instead. better yet, this logic would avoid depending on page size entirely...
2025-02-25mem: add `@branchHint` to `indexOfSentinel`David Rubin
also seems to work around aarch64 LLVM miscompilation :thinking:
2025-02-25Revert "skip regressed LLVM 17 std lib test on powerpc"Alex Rønne Petersen
This reverts commit 5b8af7a2a9140fd0533961b62addc61f57b33343. Closes #16951.
2025-02-15std: add containsAtLeastScalar to mem (#22826)LmanTW
2025-02-10std.mem: add missing check to lastIndexOfLinearandrewkraevskii
2025-02-06std: update to new Allocator APIAndrew Kelley
2025-02-06add std.mem.Alignment APIAndrew Kelley
2025-02-06adjust runtime page size APIsAndrew Kelley
* fix merge conflicts * rename the declarations * reword documentation * extract FixedBufferAllocator to separate file * take advantage of locals * remove the assertion about max alignment in Allocator API, leaving it Allocator implementation defined * fix non-inline function call in start logic The GeneralPurposeAllocator implementation is totally broken because it uses global state but I didn't address that in this commit.
2025-02-06runtime page size detectionArchbirdplus
heap.zig: define new default page sizes heap.zig: add min/max_page_size and their options lib/std/c: add miscellaneous declarations heap.zig: add pageSize() and its options switch to new page sizes, especially in GPA/stdlib mem.zig: remove page_size
2025-01-16x86_64: rewrite arithmeticJacob Young
2025-01-16all: update to `std.builtin.Type.{Pointer,Array,StructField}` field renamesmlugg
2025-01-16all: update to `std.builtin.Type.Pointer.Size` field renamesmlugg
This was done by regex substitution with `sed`. I then manually went over the entire diff and fixed any incorrect changes. This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since my regex happened to also trigger here. I opted to leave these changes in, since they *are* a correct migration, even if they're not the one I was trying to do!
2025-01-04Improve `first()` documentation for split iteratorsaxel escalada
* remove from doc., add explicit info when panic * match convention for assert documentation, avoiding to use panic here
2024-11-22std.mem: adjust semanticsAndrew Kelley
* some kinds of types require comptime calls to eql * don't rely on compare equal for undefined
2024-11-22std.mem.eql: make comparisons for zero-sized and non-sized types workAndrew Kelley
The `if (@sizeOf(T) == 0) return true;` check simply doesn't work for a number of cases so that is removed and changed into `@sizeOf(T) != 0` and then used in the `eqlBytes` check chain to make comparing `enum{}`s possible. The rest special-cases for comptime-only types and undefined to make those comparisons possible as well. Fixes #19929
2024-10-31std.mem.asBytes: fix footgun when passing non-single pointermlugg
I was just bitten by this footgun, where I actually wanted `sliceAsBytes` but unintentionally used `asBytes`, which in practice ignored all but the first element. Just add a comptime assertion to trigger a compile error in this case.
2024-10-11std.mem.readVarInt: assert ReturnType is large enough (#20946)poypoyan
Fixes #20521
2024-10-04Remove old deprecated symbols in std (#21584)PauloCampana
Also, actually run tests inside std/tar/writer.zig