http server can load static files...slowly.

Former-commit-id: 45b55a8970
This commit is contained in:
Jarred Sumner
2021-05-22 23:25:25 -07:00
parent c3d3d70ced
commit 7cc2661aa6
14 changed files with 549 additions and 131 deletions

View File

@@ -95,8 +95,11 @@ pub fn eql(self: string, other: anytype) bool {
}
return true;
}
// I have not actually verified that this makes it faster
// It's probably like 0.0001ms faster
pub fn eqlInsensitive(self: string, other: anytype) bool {
return std.ascii.eqlIgnoreCase(self, other);
}
pub fn eqlComptime(self: string, comptime alt: anytype) bool {
switch (comptime alt.len) {
0 => {
@@ -113,11 +116,11 @@ pub fn eqlComptime(self: string, comptime alt: anytype) bool {
return true;
},
4 => {
comptime const check = std.mem.readIntNative(u32, alt[0..alt.len]);
const check = std.mem.readIntNative(u32, alt[0..alt.len]);
return self.len == alt.len and std.mem.readIntNative(u32, self[0..4]) == check;
},
5...7 => {
comptime const check = std.mem.readIntNative(u32, alt[0..4]);
const check = std.mem.readIntNative(u32, alt[0..4]);
if (self.len != alt.len or std.mem.readIntNative(u32, self[0..4]) != check) {
return false;
}
@@ -128,11 +131,11 @@ pub fn eqlComptime(self: string, comptime alt: anytype) bool {
return true;
},
8 => {
comptime const check = std.mem.readIntNative(u64, alt[0..alt.len]);
const check = std.mem.readIntNative(u64, alt[0..alt.len]);
return self.len == alt.len and std.mem.readIntNative(u64, self[0..8]) == check;
},
9...11 => {
comptime const first = std.mem.readIntNative(u64, alt[0..8]);
const first = std.mem.readIntNative(u64, alt[0..8]);
if (self.len != alt.len or first != std.mem.readIntNative(u64, self[0..8])) {
return false;
@@ -144,10 +147,29 @@ pub fn eqlComptime(self: string, comptime alt: anytype) bool {
return true;
},
12 => {
comptime const first = std.mem.readIntNative(u64, alt[0..8]);
comptime const second = std.mem.readIntNative(u32, alt[8..12]);
const first = std.mem.readIntNative(u64, alt[0..8]);
const second = std.mem.readIntNative(u32, alt[8..12]);
return (self.len == alt.len) and first == std.mem.readIntNative(u64, self[0..8]) and second == std.mem.readIntNative(u32, self[8..12]);
},
13...15 => {
const first = std.mem.readIntNative(u64, alt[0..8]);
const second = std.mem.readIntNative(u32, alt[8..12]);
if (self.len != alt.len or first != std.mem.readIntNative(u64, self[0..8]) or second != std.mem.readIntNative(u32, self[8..12])) {
return false;
}
inline for (alt[13..]) |c, i| {
if (self[i + 13] != c) return false;
}
return true;
},
16 => {
const first = std.mem.readIntNative(u64, alt[0..8]);
const second = std.mem.readIntNative(u64, alt[8..15]);
return (self.len == alt.len) and first == std.mem.readIntNative(u64, self[0..8]) and second == std.mem.readIntNative(u64, self[8..16]);
},
else => {
@compileError(alt ++ " is too long.");
},