std: Rename ArrayList shrink => shrinkAndFree

This commit is contained in:
Alex Cameron 2020-12-29 16:22:22 +11:00
parent 3e8aaee829
commit 89286376c6
10 changed files with 22 additions and 22 deletions

View File

@ -323,7 +323,7 @@ pub fn ArrayHashMapUnmanaged(
}
pub fn clearAndFree(self: *Self, allocator: *Allocator) void {
self.entries.shrink(allocator, 0);
self.entries.shrinkAndFree(allocator, 0);
if (self.index_header) |header| {
header.free(allocator);
self.index_header = null;

View File

@ -269,7 +269,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
/// Reduce allocated capacity to `new_len`.
/// May invalidate element pointers.
pub fn shrink(self: *Self, new_len: usize) void {
pub fn shrinkAndFree(self: *Self, new_len: usize) void {
assert(new_len <= self.items.len);
self.items = self.allocator.realloc(self.allocatedSlice(), new_len) catch |e| switch (e) {
@ -585,7 +585,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
}
/// Reduce allocated capacity to `new_len`.
pub fn shrink(self: *Self, allocator: *Allocator, new_len: usize) void {
pub fn shrinkAndFree(self: *Self, allocator: *Allocator, new_len: usize) void {
assert(new_len <= self.items.len);
self.items = allocator.realloc(self.allocatedSlice(), new_len) catch |e| switch (e) {
@ -1153,7 +1153,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
try list.append(2);
try list.append(3);
list.shrink(1);
list.shrinkAndFree(1);
testing.expect(list.items.len == 1);
}
{
@ -1163,7 +1163,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
try list.append(a, 2);
try list.append(a, 3);
list.shrink(a, 1);
list.shrinkAndFree(a, 1);
testing.expect(list.items.len == 1);
}
}

View File

@ -2186,7 +2186,7 @@ pub const Walker = struct {
var top = &self.stack.items[self.stack.items.len - 1];
const dirname_len = top.dirname_len;
if (try top.dir_it.next()) |base| {
self.name_buffer.shrink(dirname_len);
self.name_buffer.shrinkAndFree(dirname_len);
try self.name_buffer.append(path.sep);
try self.name_buffer.appendSlice(base.name);
if (base.kind == .Directory) {

View File

@ -76,12 +76,12 @@ pub fn Reader(
start_index += bytes_read;
if (start_index - original_len > max_append_size) {
array_list.shrink(original_len + max_append_size);
array_list.shrinkAndFree(original_len + max_append_size);
return error.StreamTooLong;
}
if (bytes_read != dest_slice.len) {
array_list.shrink(start_index);
array_list.shrinkAndFree(start_index);
return;
}
@ -111,7 +111,7 @@ pub fn Reader(
delimiter: u8,
max_size: usize,
) !void {
array_list.shrink(0);
array_list.shrinkAndFree(0);
while (true) {
var byte: u8 = try self.readByte();

View File

@ -1897,7 +1897,7 @@ pub const Parser = struct {
pub fn reset(p: *Parser) void {
p.state = .Simple;
p.stack.shrink(0);
p.stack.shrinkAndFree(0);
}
pub fn parse(p: *Parser, input: []const u8) !ValueTree {

View File

@ -607,7 +607,7 @@ pub const Mutable = struct {
/// it will have the same length as it had when the function was called.
pub fn gcd(rma: *Mutable, x: Const, y: Const, limbs_buffer: *std.ArrayList(Limb)) !void {
const prev_len = limbs_buffer.items.len;
defer limbs_buffer.shrink(prev_len);
defer limbs_buffer.shrinkAndFree(prev_len);
const x_copy = if (rma.limbs.ptr == x.limbs.ptr) blk: {
const start = limbs_buffer.items.len;
try limbs_buffer.appendSlice(x.limbs);

View File

@ -1200,13 +1200,13 @@ fn linuxLookupNameFromDnsSearch(
var tok_it = mem.tokenize(search, " \t");
while (tok_it.next()) |tok| {
canon.shrink(canon_name.len + 1);
canon.shrinkAndFree(canon_name.len + 1);
try canon.appendSlice(tok);
try linuxLookupNameFromDns(addrs, canon, canon.items, family, rc, port);
if (addrs.items.len != 0) return;
}
canon.shrink(canon_name.len);
canon.shrinkAndFree(canon_name.len);
return linuxLookupNameFromDns(addrs, canon, name, family, rc, port);
}

View File

@ -735,7 +735,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
}
assert(mem.endsWith(u8, buf.items, ","));
buf.items[buf.items.len - 1] = 0;
buf.shrink(buf.items.len);
buf.shrinkAndFree(buf.items.len);
break :blk buf.items[0 .. buf.items.len - 1 :0].ptr;
} else null;

View File

@ -337,7 +337,7 @@ pub const LibCInstallation = struct {
defer result_buf.deinit();
for (searches) |search| {
result_buf.shrink(0);
result_buf.shrinkAndFree(0);
try result_buf.outStream().print("{s}\\Include\\{s}\\ucrt", .{ search.path, search.version });
var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
@ -383,7 +383,7 @@ pub const LibCInstallation = struct {
};
for (searches) |search| {
result_buf.shrink(0);
result_buf.shrinkAndFree(0);
try result_buf.outStream().print("{s}\\Lib\\{s}\\ucrt\\{s}", .{ search.path, search.version, arch_sub_dir });
var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
@ -437,7 +437,7 @@ pub const LibCInstallation = struct {
};
for (searches) |search| {
result_buf.shrink(0);
result_buf.shrinkAndFree(0);
const stream = result_buf.outStream();
try stream.print("{s}\\Lib\\{s}\\um\\{s}", .{ search.path, search.version, arch_sub_dir });

View File

@ -2846,7 +2846,7 @@ fn transCase(
// take all pending statements
try switch_scope.pending_block.statements.appendSlice(block_scope.statements.items);
block_scope.statements.shrink(0);
block_scope.statements.shrinkAndFree(0);
const pending_node = try switch_scope.pending_block.complete(rp.c);
switch_scope.pending_block.deinit();
@ -2884,7 +2884,7 @@ fn transDefault(
// take all pending statements
try switch_scope.pending_block.statements.appendSlice(block_scope.statements.items);
block_scope.statements.shrink(0);
block_scope.statements.shrinkAndFree(0);
const pending_node = try switch_scope.pending_block.complete(rp.c);
switch_scope.pending_block.deinit();
@ -4773,9 +4773,9 @@ const RestorePoint = struct {
src_buf_index: usize,
fn activate(self: RestorePoint) void {
self.c.token_ids.shrink(self.c.gpa, self.token_index);
self.c.token_locs.shrink(self.c.gpa, self.token_index);
self.c.source_buffer.shrink(self.src_buf_index);
self.c.token_ids.shrinkAndFree(self.c.gpa, self.token_index);
self.c.token_locs.shrinkAndFree(self.c.gpa, self.token_index);
self.c.source_buffer.shrinkAndFree(self.src_buf_index);
}
};