aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-01-05 17:42:16 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-01-05 17:42:16 -0700
commit38572ee89492d8499a5881d12c401d9bb0925167 (patch)
tree2ff6f00b6545697c386740032f9a32d124cfb438 /lib/std/array_list.zig
parent6c4924408b1957d493568271a0158b1190574dd0 (diff)
parent3e39d0c44fbf0cfb56ef0c00fc8ec7c0d5e1c1ec (diff)
downloadzig-38572ee89492d8499a5881d12c401d9bb0925167.tar.gz
zig-38572ee89492d8499a5881d12c401d9bb0925167.zip
Merge branch 'stage2-rework-cbe'
Reworks the C backend and -femit-h to properly participate in incremental compilation. closes #7602
Diffstat (limited to 'lib/std/array_list.zig')
-rw-r--r--lib/std/array_list.zig22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index 3114d1b744..51f5b8dc09 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -100,10 +100,20 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
/// Initializes an ArrayListUnmanaged with the `items` and `capacity` fields
/// of this ArrayList. This ArrayList retains ownership of underlying memory.
+ /// Deprecated: use `moveToUnmanaged` which has different semantics.
pub fn toUnmanaged(self: Self) ArrayListAlignedUnmanaged(T, alignment) {
return .{ .items = self.items, .capacity = self.capacity };
}
+ /// Initializes an ArrayListUnmanaged with the `items` and `capacity` fields
+ /// of this ArrayList. Empties this ArrayList.
+ pub fn moveToUnmanaged(self: *Self) ArrayListAlignedUnmanaged(T, alignment) {
+ const allocator = self.allocator;
+ const result = .{ .items = self.items, .capacity = self.capacity };
+ self.* = init(allocator);
+ return result;
+ }
+
/// The caller owns the returned memory. Empties this ArrayList.
pub fn toOwnedSlice(self: *Self) Slice {
const allocator = self.allocator;
@@ -551,14 +561,6 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
mem.copy(T, self.items[oldlen..], items);
}
- /// Same as `append` except it returns the number of bytes written, which is always the same
- /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API.
- /// This function may be called only when `T` is `u8`.
- fn appendWrite(self: *Self, allocator: *Allocator, m: []const u8) !usize {
- try self.appendSlice(allocator, m);
- return m.len;
- }
-
/// Append a value to the list `n` times.
/// Allocates more memory as necessary.
pub fn appendNTimes(self: *Self, allocator: *Allocator, value: T, n: usize) !void {
@@ -1129,13 +1131,13 @@ test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" {
}
}
-test "std.ArrayList(u8) implements outStream" {
+test "std.ArrayList(u8) implements writer" {
var buffer = ArrayList(u8).init(std.testing.allocator);
defer buffer.deinit();
const x: i32 = 42;
const y: i32 = 1234;
- try buffer.outStream().print("x: {}\ny: {}\n", .{ x, y });
+ try buffer.writer().print("x: {}\ny: {}\n", .{ x, y });
testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items);
}