Switch to ArrayHashMap
This commit is contained in:
parent
2d464f0820
commit
d2151ae326
3 changed files with 12 additions and 6 deletions
|
@ -3,24 +3,24 @@ const std = @import("std");
|
|||
pub const Fields = struct {
|
||||
const HashContext = struct {
|
||||
const hash_seed = 1;
|
||||
pub fn eql(_: @This(), lhs: []const u8, rhs: []const u8) bool {
|
||||
pub fn eql(_: @This(), lhs: []const u8, rhs: []const u8, _: usize) bool {
|
||||
return std.ascii.eqlIgnoreCase(lhs, rhs);
|
||||
}
|
||||
pub fn hash(_: @This(), s: []const u8) u64 {
|
||||
pub fn hash(_: @This(), s: []const u8) u32 {
|
||||
var h = std.hash.Wyhash.init(hash_seed);
|
||||
for (s) |ch| {
|
||||
const c = [1]u8{std.ascii.toLower(ch)};
|
||||
h.update(&c);
|
||||
}
|
||||
return h.final();
|
||||
return @truncate(u32, h.final());
|
||||
}
|
||||
};
|
||||
|
||||
const HashMap = std.HashMapUnmanaged(
|
||||
const HashMap = std.ArrayHashMapUnmanaged(
|
||||
[]const u8,
|
||||
[]const u8,
|
||||
HashContext,
|
||||
std.hash_map.default_max_load_percentage,
|
||||
true,
|
||||
);
|
||||
|
||||
unmanaged: HashMap,
|
||||
|
|
|
@ -38,7 +38,11 @@ fn writeStatusLine(writer: anytype, status: Status) !void {
|
|||
|
||||
fn writeFields(writer: anytype, headers: *const Fields) !void {
|
||||
var iter = headers.iterator();
|
||||
std.log.debug("{any}", .{headers});
|
||||
std.log.debug("{any}", .{iter});
|
||||
while (iter.next()) |header| {
|
||||
std.log.debug("{any}", .{headers});
|
||||
std.log.debug("{any}", .{iter});
|
||||
for (header.value_ptr.*) |ch| {
|
||||
if (ch == '\r' or ch == '\n') @panic("newlines not yet supported in headers");
|
||||
}
|
||||
|
@ -95,7 +99,6 @@ pub fn ResponseStream(comptime BaseWriter: type) type {
|
|||
return;
|
||||
}
|
||||
|
||||
std.debug.print("{}\n", .{cursor});
|
||||
self.writeToBuffer(bytes[cursor .. cursor + remaining_in_chunk]);
|
||||
cursor += remaining_in_chunk;
|
||||
try self.flushChunk();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const api = @import("api");
|
||||
const std = @import("std");
|
||||
|
||||
pub const login = struct {
|
||||
pub const method = .POST;
|
||||
|
@ -12,6 +13,8 @@ pub const login = struct {
|
|||
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
|
||||
const token = try srv.login(req.body.username, req.body.password);
|
||||
|
||||
std.log.debug("{any}", .{res.headers});
|
||||
|
||||
try res.json(.ok, token);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue