| ... | @@ -1196,10 +1196,12 @@ pub const Repository = struct { | ... | @@ -1196,10 +1196,12 @@ pub const Repository = struct { |
| 1196 | } | 1196 | } |
| 1197 | if (try r.getObject(arena, id.id)) |obj| { | 1197 | if (try r.getObject(arena, id.id)) |obj| { |
| 1198 | if (obj.type == .tree) { | 1198 | if (obj.type == .tree) { |
| 1199 | var children: std.MultiArrayList(Tree.Object) = .empty; | 1199 | const MAL = std.MultiArrayList(Tree.Object); |
| | 1200 | var children: MAL = .empty; |
| 1200 | errdefer children.deinit(r.gpa); | 1201 | errdefer children.deinit(r.gpa); |
| 1201 | try children.ensureUnusedCapacity(r.gpa, 33); | 1202 | try children.ensureUnusedCapacity(r.gpa, 33); |
| 1202 | var i: usize = 0; | 1203 | var i: usize = 0; |
| | 1204 | var slice = children.slice(); |
| 1203 | while (i < obj.content.len) { | 1205 | while (i < obj.content.len) { |
| 1204 | const mode_end = std.mem.indexOfScalar(u8, obj.content[i..], ' ').?; | 1206 | const mode_end = std.mem.indexOfScalar(u8, obj.content[i..], ' ').?; |
| 1205 | const mode = obj.content[i..][0..mode_end]; | 1207 | const mode = obj.content[i..][0..mode_end]; |
| ... | @@ -1218,7 +1220,15 @@ pub const Repository = struct { | ... | @@ -1218,7 +1220,15 @@ pub const Repository = struct { |
| 1218 | @memcpy(mode_buf[6 - mode.len ..], mode); | 1220 | @memcpy(mode_buf[6 - mode.len ..], mode); |
| 1219 | const mode_real = try parseTreeMode(&mode_buf); | 1221 | const mode_real = try parseTreeMode(&mode_buf); |
| 1220 | | 1222 | |
| 1221 | try children.append(r.gpa, .{ | 1223 | const j = slice.len; |
| | 1224 | if (j == slice.capacity) { |
| | 1225 | @branchHint(.cold); |
| | 1226 | try children.ensureUnusedCapacity(r.gpa, 1); |
| | 1227 | slice = children.slice(); |
| | 1228 | } |
| | 1229 | children.len += 1; |
| | 1230 | slice.len += 1; |
| | 1231 | slice.set(j, .{ |
| 1222 | .mode = mode_real, | 1232 | .mode = mode_real, |
| 1223 | .name = name, | 1233 | .name = name, |
| 1224 | .id = switch (mode_real.type) { | 1234 | .id = switch (mode_real.type) { |
| ... | @@ -1232,7 +1242,7 @@ pub const Repository = struct { | ... | @@ -1232,7 +1242,7 @@ pub const Repository = struct { |
| 1232 | } | 1242 | } |
| 1233 | | 1243 | |
| 1234 | const S = struct { | 1244 | const S = struct { |
| 1235 | list: *std.MultiArrayList(Tree.Object), | 1245 | list: *MAL, |
| 1236 | | 1246 | |
| 1237 | pub fn lessThan(s: @This(), a: usize, b: usize) bool { | 1247 | pub fn lessThan(s: @This(), a: usize, b: usize) bool { |
| 1238 | const items = s.list.items(.name); | 1248 | const items = s.list.items(.name); |
| ... | @@ -1241,7 +1251,7 @@ pub const Repository = struct { | ... | @@ -1241,7 +1251,7 @@ pub const Repository = struct { |
| 1241 | pub fn swap(s: @This(), a: usize, b: usize) void { | 1251 | pub fn swap(s: @This(), a: usize, b: usize) void { |
| 1242 | // Remove after updating to Zig 0.17. Ref: https://codeberg.org/ziglang/zig/pulls/32016 | 1252 | // Remove after updating to Zig 0.17. Ref: https://codeberg.org/ziglang/zig/pulls/32016 |
| 1243 | inline for (@typeInfo(Tree.Object).@"struct".fields) |field| { | 1253 | inline for (@typeInfo(Tree.Object).@"struct".fields) |field| { |
| 1244 | const its = s.list.items(@field(std.MultiArrayList(Tree.Object).Field, field.name)); | 1254 | const its = s.list.items(@field(MAL.Field, field.name)); |
| 1245 | std.mem.swap(@FieldType(Tree.Object, field.name), &its[a], &its[b]); | 1255 | std.mem.swap(@FieldType(Tree.Object, field.name), &its[a], &its[b]); |
| 1246 | } | 1256 | } |
| 1247 | } | 1257 | } |