Skip to content

ComptimeStringMap: return a regular struct and optimize #19719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/c/linux.zig"
"${CMAKE_SOURCE_DIR}/lib/std/child_process.zig"
"${CMAKE_SOURCE_DIR}/lib/std/coff.zig"
"${CMAKE_SOURCE_DIR}/lib/std/comptime_string_map.zig"
"${CMAKE_SOURCE_DIR}/lib/std/static_string_map.zig"
"${CMAKE_SOURCE_DIR}/lib/std/crypto.zig"
"${CMAKE_SOURCE_DIR}/lib/std/crypto/blake3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/crypto/siphash.zig"
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/aro/aro/LangOpts.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub const Standard = enum {
/// Working Draft for ISO C23 with GNU extensions
gnu23,

const NameMap = std.ComptimeStringMap(Standard, .{
const NameMap = std.StaticStringMap(Standard).initComptime(.{
.{ "c89", .c89 }, .{ "c90", .c89 }, .{ "iso9899:1990", .c89 },
.{ "iso9899:199409", .iso9899 }, .{ "gnu89", .gnu89 }, .{ "gnu90", .gnu89 },
.{ "c99", .c99 }, .{ "iso9899:1999", .c99 }, .{ "c9x", .c99 },
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/aro/aro/Preprocessor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ fn expandFuncMacro(
}
if (!pp.comp.langopts.standard.atLeast(.c23)) break :res not_found;

const attrs = std.ComptimeStringMap([]const u8, .{
const attrs = std.StaticStringMap([]const u8).initComptime(.{
.{ "deprecated", "201904L\n" },
.{ "fallthrough", "201904L\n" },
.{ "maybe_unused", "201904L\n" },
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/aro/aro/Tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ pub const Token = struct {
};
}

const all_kws = std.ComptimeStringMap(Id, .{
const all_kws = std.StaticStringMap(Id).initComptime(.{
.{ "auto", auto: {
@setEvalBranchQuota(3000);
break :auto .keyword_auto;
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/resinator/errors.zig
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ pub const ErrorDetails = struct {
// see https://github.com/ziglang/zig/issues/15395
_: u26 = 0,

pub const strings = std.ComptimeStringMap([]const u8, .{
pub const strings = std.StaticStringMap([]const u8).initComptime(.{
.{ "number", "number" },
.{ "number_expression", "number expression" },
.{ "string_literal", "quoted string literal" },
Expand Down
91 changes: 65 additions & 26 deletions lib/compiler/resinator/rc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ pub const Resource = enum {
fontdir_num,
manifest_num,

const map = std.ComptimeStringMapWithEql(Resource, .{
const map = std.StaticStringMapWithEql(
Resource,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "ACCELERATORS", .accelerators },
.{ "BITMAP", .bitmap },
.{ "CURSOR", .cursor },
Expand All @@ -67,7 +70,7 @@ pub const Resource = enum {
.{ "TOOLBAR", .toolbar },
.{ "VERSIONINFO", .versioninfo },
.{ "VXD", .vxd },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});

pub fn fromString(bytes: SourceBytes) Resource {
const maybe_ordinal = res.NameOrOrdinal.maybeOrdinalFromString(bytes);
Expand Down Expand Up @@ -157,20 +160,26 @@ pub const OptionalStatements = enum {
menu,
style,

pub const map = std.ComptimeStringMapWithEql(OptionalStatements, .{
pub const map = std.StaticStringMapWithEql(
OptionalStatements,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "CHARACTERISTICS", .characteristics },
.{ "LANGUAGE", .language },
.{ "VERSION", .version },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});

pub const dialog_map = std.ComptimeStringMapWithEql(OptionalStatements, .{
pub const dialog_map = std.StaticStringMapWithEql(
OptionalStatements,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "CAPTION", .caption },
.{ "CLASS", .class },
.{ "EXSTYLE", .exstyle },
.{ "FONT", .font },
.{ "MENU", .menu },
.{ "STYLE", .style },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});
};

pub const Control = enum {
Expand All @@ -197,7 +206,10 @@ pub const Control = enum {
state3,
userbutton,

pub const map = std.ComptimeStringMapWithEql(Control, .{
pub const map = std.StaticStringMapWithEql(
Control,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "AUTO3STATE", .auto3state },
.{ "AUTOCHECKBOX", .autocheckbox },
.{ "AUTORADIOBUTTON", .autoradiobutton },
Expand All @@ -220,7 +232,7 @@ pub const Control = enum {
.{ "SCROLLBAR", .scrollbar },
.{ "STATE3", .state3 },
.{ "USERBUTTON", .userbutton },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});

pub fn hasTextParam(control: Control) bool {
switch (control) {
Expand All @@ -231,14 +243,17 @@ pub const Control = enum {
};

pub const ControlClass = struct {
pub const map = std.ComptimeStringMapWithEql(res.ControlClass, .{
pub const map = std.StaticStringMapWithEql(
res.ControlClass,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "BUTTON", .button },
.{ "EDIT", .edit },
.{ "STATIC", .static },
.{ "LISTBOX", .listbox },
.{ "SCROLLBAR", .scrollbar },
.{ "COMBOBOX", .combobox },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});

/// Like `map.get` but works on WTF16 strings, for use with parsed
/// string literals ("BUTTON", or even "\x42UTTON")
Expand Down Expand Up @@ -280,10 +295,13 @@ pub const MenuItem = enum {
menuitem,
popup,

pub const map = std.ComptimeStringMapWithEql(MenuItem, .{
pub const map = std.StaticStringMapWithEql(
MenuItem,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "MENUITEM", .menuitem },
.{ "POPUP", .popup },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});

pub fn isSeparator(bytes: []const u8) bool {
return std.ascii.eqlIgnoreCase(bytes, "SEPARATOR");
Expand All @@ -297,25 +315,31 @@ pub const MenuItem = enum {
menubarbreak,
menubreak,

pub const map = std.ComptimeStringMapWithEql(Option, .{
pub const map = std.StaticStringMapWithEql(
Option,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "CHECKED", .checked },
.{ "GRAYED", .grayed },
.{ "HELP", .help },
.{ "INACTIVE", .inactive },
.{ "MENUBARBREAK", .menubarbreak },
.{ "MENUBREAK", .menubreak },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});
};
};

pub const ToolbarButton = enum {
button,
separator,

pub const map = std.ComptimeStringMapWithEql(ToolbarButton, .{
pub const map = std.StaticStringMapWithEql(
ToolbarButton,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "BUTTON", .button },
.{ "SEPARATOR", .separator },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});
};

pub const VersionInfo = enum {
Expand All @@ -327,25 +351,31 @@ pub const VersionInfo = enum {
file_type,
file_subtype,

pub const map = std.ComptimeStringMapWithEql(VersionInfo, .{
pub const map = std.StaticStringMapWithEql(
VersionInfo,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "FILEVERSION", .file_version },
.{ "PRODUCTVERSION", .product_version },
.{ "FILEFLAGSMASK", .file_flags_mask },
.{ "FILEFLAGS", .file_flags },
.{ "FILEOS", .file_os },
.{ "FILETYPE", .file_type },
.{ "FILESUBTYPE", .file_subtype },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});
};

pub const VersionBlock = enum {
block,
value,

pub const map = std.ComptimeStringMapWithEql(VersionBlock, .{
pub const map = std.StaticStringMapWithEql(
VersionBlock,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "BLOCK", .block },
.{ "VALUE", .value },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});
};

/// Keywords that are be the first token in a statement and (if so) dictate how the rest
Expand All @@ -356,12 +386,15 @@ pub const TopLevelKeywords = enum {
characteristics,
stringtable,

pub const map = std.ComptimeStringMapWithEql(TopLevelKeywords, .{
pub const map = std.StaticStringMapWithEql(
TopLevelKeywords,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "LANGUAGE", .language },
.{ "VERSION", .version },
.{ "CHARACTERISTICS", .characteristics },
.{ "STRINGTABLE", .stringtable },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});
};

pub const CommonResourceAttributes = enum {
Expand All @@ -375,7 +408,10 @@ pub const CommonResourceAttributes = enum {
shared,
nonshared,

pub const map = std.ComptimeStringMapWithEql(CommonResourceAttributes, .{
pub const map = std.StaticStringMapWithEql(
CommonResourceAttributes,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "PRELOAD", .preload },
.{ "LOADONCALL", .loadoncall },
.{ "FIXED", .fixed },
Expand All @@ -385,7 +421,7 @@ pub const CommonResourceAttributes = enum {
.{ "IMPURE", .impure },
.{ "SHARED", .shared },
.{ "NONSHARED", .nonshared },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});
};

pub const AcceleratorTypeAndOptions = enum {
Expand All @@ -396,12 +432,15 @@ pub const AcceleratorTypeAndOptions = enum {
shift,
control,

pub const map = std.ComptimeStringMapWithEql(AcceleratorTypeAndOptions, .{
pub const map = std.StaticStringMapWithEql(
AcceleratorTypeAndOptions,
std.static_string_map.eqlAsciiIgnoreCase,
).initComptime(.{
.{ "VIRTKEY", .virtkey },
.{ "ASCII", .ascii },
.{ "NOINVERT", .noinvert },
.{ "ALT", .alt },
.{ "SHIFT", .shift },
.{ "CONTROL", .control },
}, std.comptime_string_map.eqlAsciiIgnoreCase);
});
};
Loading