Skip to content

Commit 982f5af

Browse files
committed
Update all std.mem.split calls to their appropriate function
Everywhere that can now use `splitScalar` should get a nice little performance boost.
1 parent 69f0a08 commit 982f5af

27 files changed

+58
-55
lines changed

build.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub fn build(b: *std.Build) !void {
239239
},
240240
2 => {
241241
// Untagged development build (e.g. 0.10.0-dev.2025+ecf0050a9).
242-
var it = mem.split(u8, git_describe, "-");
242+
var it = mem.splitScalar(u8, git_describe, '-');
243243
const tagged_ancestor = it.first();
244244
const commit_height = it.next().?;
245245
const commit_id = it.next().?;
@@ -859,14 +859,14 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig {
859859
while (lines_it.next()) |line| {
860860
inline for (mappings) |mapping| {
861861
if (mem.startsWith(u8, line, mapping.prefix)) {
862-
var it = mem.split(u8, line, "\"");
862+
var it = mem.splitScalar(u8, line, '"');
863863
_ = it.first(); // skip the stuff before the quote
864864
const quoted = it.next().?; // the stuff inside the quote
865865
@field(ctx, mapping.field) = toNativePathSep(b, quoted);
866866
}
867867
}
868868
if (mem.startsWith(u8, line, "#define ZIG_LLVM_LINK_MODE ")) {
869-
var it = mem.split(u8, line, "\"");
869+
var it = mem.splitScalar(u8, line, '"');
870870
_ = it.next().?; // skip the stuff before the quote
871871
const quoted = it.next().?; // the stuff inside the quote
872872
ctx.llvm_linkage = if (mem.eql(u8, quoted, "shared")) .dynamic else .static;

doc/docgen.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void {
12231223
const trimmed_shell_content = mem.trim(u8, shell_content, " \n");
12241224
try out.writeAll("<figure><figcaption class=\"shell-cap\">Shell</figcaption><pre><samp>");
12251225
var cmd_cont: bool = false;
1226-
var iter = std.mem.split(u8, trimmed_shell_content, "\n");
1226+
var iter = std.mem.splitScalar(u8, trimmed_shell_content, '\n');
12271227
while (iter.next()) |orig_line| {
12281228
const line = mem.trimRight(u8, orig_line, " ");
12291229
if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] != '\\') {

lib/std/Build/Step/Compile.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,7 @@ fn checkCompileErrors(self: *Compile) !void {
21402140
// Render the expected lines into a string that we can compare verbatim.
21412141
var expected_generated = std.ArrayList(u8).init(arena);
21422142

2143-
var actual_line_it = mem.split(u8, actual_stderr, "\n");
2143+
var actual_line_it = mem.splitScalar(u8, actual_stderr, '\n');
21442144
for (self.expect_errors) |expect_line| {
21452145
const actual_line = actual_line_it.next() orelse {
21462146
try expected_generated.appendSlice(expect_line);

lib/std/Build/Step/ConfigHeader.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ fn render_autoconf(
250250

251251
var any_errors = false;
252252
var line_index: u32 = 0;
253-
var line_it = std.mem.split(u8, contents, "\n");
253+
var line_it = std.mem.splitScalar(u8, contents, '\n');
254254
while (line_it.next()) |line| : (line_index += 1) {
255255
if (!std.mem.startsWith(u8, line, "#")) {
256256
try output.appendSlice(line);
@@ -297,7 +297,7 @@ fn render_cmake(
297297

298298
var any_errors = false;
299299
var line_index: u32 = 0;
300-
var line_it = std.mem.split(u8, contents, "\n");
300+
var line_it = std.mem.splitScalar(u8, contents, '\n');
301301
while (line_it.next()) |line| : (line_index += 1) {
302302
if (!std.mem.startsWith(u8, line, "#")) {
303303
try output.appendSlice(line);

lib/std/SemanticVersion.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ pub fn order(lhs: Version, rhs: Version) std.math.Order {
4242
if (lhs.pre == null and rhs.pre != null) return .gt;
4343

4444
// Iterate over pre-release identifiers until a difference is found.
45-
var lhs_pre_it = std.mem.split(u8, lhs.pre.?, ".");
46-
var rhs_pre_it = std.mem.split(u8, rhs.pre.?, ".");
45+
var lhs_pre_it = std.mem.splitScalar(u8, lhs.pre.?, '.');
46+
var rhs_pre_it = std.mem.splitScalar(u8, rhs.pre.?, '.');
4747
while (true) {
4848
const next_lid = lhs_pre_it.next();
4949
const next_rid = rhs_pre_it.next();
@@ -86,7 +86,7 @@ pub fn parse(text: []const u8) !Version {
8686
// Parse the required major, minor, and patch numbers.
8787
const extra_index = std.mem.indexOfAny(u8, text, "-+");
8888
const required = text[0..(extra_index orelse text.len)];
89-
var it = std.mem.split(u8, required, ".");
89+
var it = std.mem.splitScalar(u8, required, '.');
9090
var ver = Version{
9191
.major = try parseNum(it.first()),
9292
.minor = try parseNum(it.next() orelse return error.InvalidVersion),
@@ -108,7 +108,7 @@ pub fn parse(text: []const u8) !Version {
108108
// Check validity of optional pre-release identifiers.
109109
// See: https://semver.org/#spec-item-9
110110
if (ver.pre) |pre| {
111-
it = std.mem.split(u8, pre, ".");
111+
it = std.mem.splitScalar(u8, pre, '.');
112112
while (it.next()) |id| {
113113
// Identifiers MUST NOT be empty.
114114
if (id.len == 0) return error.InvalidVersion;
@@ -127,7 +127,7 @@ pub fn parse(text: []const u8) !Version {
127127
// Check validity of optional build metadata identifiers.
128128
// See: https://semver.org/#spec-item-10
129129
if (ver.build) |build| {
130-
it = std.mem.split(u8, build, ".");
130+
it = std.mem.splitScalar(u8, build, '.');
131131
while (it.next()) |id| {
132132
// Identifiers MUST NOT be empty.
133133
if (id.len == 0) return error.InvalidVersion;

lib/std/builtin.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ pub const Version = struct {
531531
// found no digits or '.' before unexpected character
532532
if (end == 0) return error.InvalidVersion;
533533

534-
var it = std.mem.split(u8, text[0..end], ".");
534+
var it = std.mem.splitScalar(u8, text[0..end], '.');
535535
// substring is not empty, first call will succeed
536536
const major = it.first();
537537
if (major.len == 0) return error.InvalidVersion;

lib/std/crypto/Certificate.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ pub const Parsed = struct {
337337
return true; // exact match
338338
}
339339

340-
var it_host = std.mem.split(u8, host_name, ".");
341-
var it_dns = std.mem.split(u8, dns_name, ".");
340+
var it_host = std.mem.splitScalar(u8, host_name, '.');
341+
var it_dns = std.mem.splitScalar(u8, dns_name, '.');
342342

343343
const len_match = while (true) {
344344
const host = it_host.next();

lib/std/crypto/phc_encoding.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ const mem = std.mem;
77
const meta = std.meta;
88

99
const fields_delimiter = "$";
10+
const fields_delimiter_scalar = '$';
1011
const version_param_name = "v";
1112
const params_delimiter = ",";
13+
const params_delimiter_scalar = ',';
1214
const kv_delimiter = "=";
15+
const kv_delimiter_scalar = '=';
1316

1417
pub const Error = std.crypto.errors.EncodingError || error{NoSpaceLeft};
1518

@@ -73,7 +76,7 @@ pub fn BinValue(comptime max_len: usize) type {
7376
/// Other fields will also be deserialized from the function parameters section.
7477
pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult {
7578
var out = mem.zeroes(HashResult);
76-
var it = mem.split(u8, str, fields_delimiter);
79+
var it = mem.splitScalar(u8, str, fields_delimiter_scalar);
7780
var set_fields: usize = 0;
7881

7982
while (true) {
@@ -104,7 +107,7 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
104107

105108
// Read optional parameters
106109
var has_params = false;
107-
var it_params = mem.split(u8, field, params_delimiter);
110+
var it_params = mem.splitScalar(u8, field, params_delimiter_scalar);
108111
while (it_params.next()) |params| {
109112
const param = kvSplit(params) catch break;
110113
var found = false;
@@ -252,7 +255,7 @@ fn serializeTo(params: anytype, out: anytype) !void {
252255

253256
// Split a `key=value` string into `key` and `value`
254257
fn kvSplit(str: []const u8) !struct { key: []const u8, value: []const u8 } {
255-
var it = mem.split(u8, str, kv_delimiter);
258+
var it = mem.splitScalar(u8, str, kv_delimiter_scalar);
256259
const key = it.first();
257260
const value = it.next() orelse return Error.InvalidEncoding;
258261
const ret = .{ .key = key, .value = value };

lib/std/crypto/scrypt.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ const crypt_format = struct {
287287
out.r = try Codec.intDecode(u30, str[4..9]);
288288
out.p = try Codec.intDecode(u30, str[9..14]);
289289

290-
var it = mem.split(u8, str[14..], "$");
290+
var it = mem.splitScalar(u8, str[14..], '$');
291291

292292
const salt = it.first();
293293
if (@hasField(T, "salt")) out.salt = salt;

lib/std/http/Client.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ pub const Response = struct {
406406
} else if (std.ascii.eqlIgnoreCase(header_name, "transfer-encoding")) {
407407
// Transfer-Encoding: second, first
408408
// Transfer-Encoding: deflate, chunked
409-
var iter = mem.splitBackwards(u8, header_value, ",");
409+
var iter = mem.splitBackwardsScalar(u8, header_value, ',');
410410

411411
if (iter.next()) |first| {
412412
const trimmed = mem.trim(u8, first, " ");

0 commit comments

Comments
 (0)