Use std.mem.Allocator.dupe instead of @memcpy.
This commit is contained in:
@@ -51,8 +51,7 @@ pub const Property = struct {
|
|||||||
.points => |slice| .{
|
.points => |slice| .{
|
||||||
.data = .{
|
.data = .{
|
||||||
.points = blk: {
|
.points = blk: {
|
||||||
const copy = try allocator.alloc(Point2_f, slice.len);
|
const copy = try allocator.dupe(Point2_f, slice);
|
||||||
@memcpy(copy, slice);
|
|
||||||
break :blk copy;
|
break :blk copy;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ fn appendShapeProperties(allocator: std.mem.Allocator, obj: *Object, props: []co
|
|||||||
for (props) |prop| {
|
for (props) |prop| {
|
||||||
if (prop.data == .points) {
|
if (prop.data == .points) {
|
||||||
const pts = prop.data.points;
|
const pts = prop.data.points;
|
||||||
const copy = try allocator.alloc(Point2_f, pts.len);
|
const copy = try allocator.dupe(Point2_f, pts);
|
||||||
@memcpy(copy, pts);
|
|
||||||
try obj.properties.append(allocator, .{ .data = .{ .points = copy } });
|
try obj.properties.append(allocator, .{ .data = .{ .points = copy } });
|
||||||
} else {
|
} else {
|
||||||
try obj.properties.append(allocator, prop);
|
try obj.properties.append(allocator, prop);
|
||||||
|
|||||||
@@ -84,8 +84,7 @@ fn randomizeObjectProperties(allocator: std.mem.Allocator, doc_size: *const Size
|
|||||||
x += randFloat(rng, -40, 80);
|
x += randFloat(rng, -40, 80);
|
||||||
y += randFloat(rng, -30, 60);
|
y += randFloat(rng, -30, 60);
|
||||||
}
|
}
|
||||||
const slice = try allocator.alloc(Point2_f, list.items.len);
|
const slice = try allocator.dupe(Point2_f, list.items);
|
||||||
@memcpy(slice, list.items);
|
|
||||||
try obj.setProperty(allocator, .{ .data = .{ .points = slice } });
|
try obj.setProperty(allocator, .{ .data = .{ .points = slice } });
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -676,8 +676,7 @@ fn drawPropertyEditor(canvas: *Canvas, obj: *Document.Object, prop: *const Prope
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
const slice = canvas.allocator.alloc(Point2_f, list.items.len) catch return;
|
const slice = canvas.allocator.dupe(Point2_f, list.items) catch return;
|
||||||
@memcpy(slice, list.items);
|
|
||||||
obj.setProperty(canvas.allocator, .{ .data = .{ .points = slice } }) catch {
|
obj.setProperty(canvas.allocator, .{ .data = .{ .points = slice } }) catch {
|
||||||
canvas.allocator.free(slice);
|
canvas.allocator.free(slice);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user