@@ -605,10 +605,12 @@ const AcceptHeaderList = std.ArrayList(AcceptItem);
605
605
606
606
/// Parses `Accept:` http header into `list`, ordered from highest q factor to lowest
607
607
pub fn parseAcceptHeaders (self : * const Self , allocator : std.mem.Allocator ) ! AcceptHeaderList {
608
- var list = AcceptHeaderList .init (allocator );
609
- errdefer list .deinit ();
608
+ const accept_str = self .getHeaderCommon (.accept ) orelse return error .NoAcceptHeader ;
609
+
610
+ const comma_count = std .mem .count (u8 , accept_str , "," );
610
611
611
- const accept_str = self .getHeaderCommon (.accept ) orelse return error .NoAccept ;
612
+ var list = try AcceptHeaderList .initCapacity (allocator , comma_count + 1 );
613
+ errdefer list .deinit ();
612
614
613
615
var tok_iter = std .mem .tokenize (u8 , accept_str , ", " );
614
616
while (tok_iter .next ()) | tok | {
@@ -637,11 +639,11 @@ pub fn parseAcceptHeaders(self: *const Self, allocator: std.mem.Allocator) !Acce
637
639
};
638
640
for (list .items , 1.. ) | item , i | {
639
641
if (AcceptItem .lessThan ({}, new_item , item )) {
640
- try list .insert (i , new_item );
642
+ list .insertAssumeCapacity (i , new_item );
641
643
break ;
642
644
}
643
645
} else {
644
- try list .append (new_item );
646
+ list .appendAssumeCapacity (new_item );
645
647
}
646
648
}
647
649
return list ;
0 commit comments