From 8c0bd9996d16c7a625eab9ce3ca93714802d472d Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 7 Jun 2021 03:30:37 -0700 Subject: [PATCH] use const arrays everywhere for more immutability --- src/util/dep.zig | 10 +++++----- src/util/funcs.zig | 2 +- src/util/modfile.zig | 10 +++++----- src/util/module.zig | 10 +++++----- src/util/yaml.zig | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/util/dep.zig b/src/util/dep.zig index 65371463b04203507cce8f5b1fd053aaab3cac59..00209771c16c1dfb0af3001b872dabbbcc10e719 100644 --- a/src/util/dep.zig +++ b/src/util/dep.zig @@ -18,11 +18,11 @@ pub const Dep = struct { name: []const u8, main: []const u8, version: []const u8, - c_include_dirs: [][]const u8, - c_source_flags: [][]const u8, - c_source_files: [][]const u8, - only_os: [][]const u8, - except_os: [][]const u8, + c_include_dirs: []const []const u8, + c_source_flags: []const []const u8, + c_source_files: []const []const u8, + only_os: []const []const u8, + except_os: []const []const u8, yaml: ?yaml.Mapping, pub fn clean_path(self: Dep) ![]const u8 { diff --git a/src/util/funcs.zig b/src/util/funcs.zig index b5f5cba26ce89f7ea0894d23bac15cec07c3f04a..80cbba3ea58418e0017c1836578f23a0b60d3e20 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -123,7 +123,7 @@ pub fn print_all(w: std.fs.File.Writer, items: anytype, ln: bool) !void { } } -pub fn list_contains(haystack: [][]const u8, needle: []const u8) bool { +pub fn list_contains(haystack: []const []const u8, needle: []const u8) bool { for (haystack) |item| { if (std.mem.eql(u8, item, needle)) { return true; diff --git a/src/util/modfile.zig b/src/util/modfile.zig index ca58abbb0e736b40a2630906322aafb1b7615130..a078dc7895e41d7fd518f0d3ca81025cb4e13628 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -17,14 +17,14 @@ pub const ModFile = struct { id: []const u8, name: []const u8, main: []const u8, - c_include_dirs: [][]const u8, - c_source_flags: [][]const u8, - c_source_files: [][]const u8, + c_include_dirs: []const []const u8, + c_source_flags: []const []const u8, + c_source_files: []const []const u8, deps: []const u.Dep, yaml: yaml.Mapping, devdeps: []const u.Dep, - root_files: [][]const u8, - files: [][]const u8, + root_files: []const []const u8, + files: []const []const u8, pub fn init(alloc: *std.mem.Allocator, fpath: []const u8) !Self { // diff --git a/src/util/module.zig b/src/util/module.zig index 04df5928ef9679d67a223ef6192def94c132010c..3e1fa46b098de4aeb1ab2018c4ba6c7ca74f02e8 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -13,11 +13,11 @@ pub const Module = struct { id: []const u8, name: []const u8, main: []const u8, - c_include_dirs: [][]const u8, - c_source_flags: [][]const u8, - c_source_files: [][]const u8, - only_os: [][]const u8, - except_os: [][]const u8, + c_include_dirs: []const []const u8, + c_source_flags: []const []const u8, + c_source_files: []const []const u8, + only_os: []const []const u8, + except_os: []const []const u8, yaml: ?yaml.Mapping, deps: []Module, diff --git a/src/util/yaml.zig b/src/util/yaml.zig index a4a1c0753ab27f3564474e475e8a093ae327d513..5cc73db95e094ff6f0bf7a9fbc3dddc16201cebb 100644 --- a/src/util/yaml.zig +++ b/src/util/yaml.zig @@ -8,7 +8,7 @@ const u = @import("./index.zig"); // // -const Array = [][]const u8; +const Array = []const []const u8; pub const Document = struct { mapping: Mapping, @@ -18,7 +18,7 @@ pub const Item = union(enum) { event: c.yaml_event_t, kv: Key, mapping: Mapping, - sequence: []Item, + sequence: []const Item, document: Document, string: []const u8, @@ -54,7 +54,7 @@ pub const Key = struct { pub const Value = union(enum) { string: []const u8, mapping: Mapping, - sequence: []Item, + sequence: []const Item, pub fn format(self: Value, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) @TypeOf(writer).Error!void { try writer.writeAll("Value{"); @@ -78,7 +78,7 @@ pub const Value = union(enum) { }; pub const Mapping = struct { - items: []Key, + items: []const Key, pub fn get(self: Mapping, k: []const u8) ?Value { for (self.items) |item| { -- 2.54.0