-
Notifications
You must be signed in to change notification settings - Fork 27
Feature/std os windows guid #12
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
base: main
Are you sure you want to change the base?
Conversation
|
Your branch made me realize that I should have been importing I rebased your commits and added an additional one that removes For some reason this this is causing |
b2842b1 to
4c21952
Compare
* custom parsing because Guid.parse expects curly braces.
* requires win32jsongen feature guid-with-curly-braces
4c21952 to
6ab2afb
Compare
|
@marler8997 Thank you for considering my PR. My first commit made it work, without any changes. |
|
Ok, well the commit I added should also work, it just adds the curly braces when generating the code. However it's still making my Here's the perf test app for reference: const builtin = @import("builtin");
const std = @import("std");
pub fn main() void {
comptime {
const count = 1000000;
@setEvalBranchQuota(count * 3);
var i: usize = 0;
while (i < count) : (i += 1) {
//_ = std.os.windows.GUID.parse("{aa7a8931-80e4-4fec-8f3b-553f87b4966e}");
_ = Guid.parse("aa7a8931-80e4-4fec-8f3b-553f87b4966e");
}
}
}
// TODO: this should probably be in the standard lib somewhere?
pub const Guid = extern union {
Ints: extern struct {
a: u32,
b: u16,
c: u16,
d: [8]u8,
},
Bytes: [16]u8,
const big_endian_hex_offsets = [16] u6 {0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34};
const little_endian_hex_offsets = [16] u6 {
6, 4, 2, 0,
11, 9,
16, 14,
19, 21, 24, 26, 28, 30, 32, 34};
const hex_offsets = switch (builtin.target.cpu.arch.endian()) {
.Big => big_endian_hex_offsets,
.Little => little_endian_hex_offsets,
};
pub fn parse(s: []const u8) Guid {
var guid = Guid { .Bytes = undefined };
for (hex_offsets) |hex_offset, i| {
//guid.Bytes[i] = decodeHexByte(s[offset..offset+2]);
guid.Bytes[i] = decodeHexByte([2]u8 { s[hex_offset], s[hex_offset+1] });
}
return guid;
}
};
comptime { std.debug.assert(@sizeOf(Guid) == 16); }
// TODO: is this in the standard lib somewhere?
fn hexVal(c: u8) u4 {
if (c <= '9') return @intCast(u4, c - '0');
if (c >= 'a') return @intCast(u4, c + 10 - 'a');
return @intCast(u4, c + 10 - 'A');
}
// TODO: is this in the standard lib somewhere?
fn decodeHexByte(hex: [2]u8) u8 {
return @intCast(u8, hexVal(hex[0])) << 4 | hexVal(hex[1]);
}
|
|
Ok I've grepped all of |
|
I've submitted a PR to create a benchmark for Once that's in I'll see about replacing the implementation in |
I ran both versions against my 0.14.0 zig setup, and both run in about the same time. (there aren't any timers doing actual measurement so it's hard to tell precisely) |
|
Yeah, looks like my changes to improve std guid performance are still intact. We could move to it. It doesn't look like the gotta-go-fast benchmark is still running though, so we'll need to be vigilant and looking out for whether the performance regresses again. |
No description provided.