Reorder args in decref

This commit is contained in:
Richard Feldman 2021-05-24 22:06:35 -04:00
parent 65542149a3
commit aa96d2373b
4 changed files with 16 additions and 16 deletions

View file

@ -93,11 +93,11 @@ const Alignment = packed enum(u8) {
}; };
pub fn decref( pub fn decref(
alignment: Alignment,
bytes_or_null: ?[*]u8, bytes_or_null: ?[*]u8,
data_bytes: usize, data_bytes: usize,
alignment: Alignment,
) void { ) void {
return utils.decref(alignment.toU32(), bytes_or_null, data_bytes); return utils.decref(bytes_or_null, data_bytes, alignment.toU32());
} }
pub fn allocateWithRefcount( pub fn allocateWithRefcount(
@ -199,7 +199,7 @@ pub const RocDict = extern struct {
}; };
// NOTE we fuse an increment of all keys/values with a decrement of the input dict // NOTE we fuse an increment of all keys/values with a decrement of the input dict
decref(alignment, self.dict_bytes, self.capacity() * slotSize(key_width, value_width)); decref(self.dict_bytes, self.capacity() * slotSize(key_width, value_width), alignment);
return result; return result;
} }
@ -251,7 +251,7 @@ pub const RocDict = extern struct {
// NOTE we fuse an increment of all keys/values with a decrement of the input dict // NOTE we fuse an increment of all keys/values with a decrement of the input dict
const data_bytes = self.capacity() * slotSize(key_width, value_width); const data_bytes = self.capacity() * slotSize(key_width, value_width);
decref(alignment, self.dict_bytes, data_bytes); decref(self.dict_bytes, data_bytes, alignment);
return new_dict; return new_dict;
} }
@ -497,7 +497,7 @@ pub fn dictRemove(input: RocDict, alignment: Alignment, key: Opaque, key_width:
// if the dict is now completely empty, free its allocation // if the dict is now completely empty, free its allocation
if (dict.dict_entries_len == 0) { if (dict.dict_entries_len == 0) {
const data_bytes = dict.capacity() * slotSize(key_width, value_width); const data_bytes = dict.capacity() * slotSize(key_width, value_width);
decref(alignment, dict.dict_bytes, data_bytes); decref(dict.dict_bytes, data_bytes, alignment);
output.* = RocDict.empty(); output.* = RocDict.empty();
return; return;
} }
@ -754,7 +754,7 @@ pub fn setFromList(list: RocList, alignment: Alignment, key_width: usize, value_
// NOTE: decref checks for the empty case // NOTE: decref checks for the empty case
const data_bytes = size * key_width; const data_bytes = size * key_width;
decref(alignment, list.bytes, data_bytes); decref(list.bytes, data_bytes, alignment);
} }
pub fn dictWalk( pub fn dictWalk(

View file

@ -73,7 +73,7 @@ pub const RocList = extern struct {
// NOTE we fuse an increment of all keys/values with a decrement of the input dict // NOTE we fuse an increment of all keys/values with a decrement of the input dict
const data_bytes = self.len() * element_width; const data_bytes = self.len() * element_width;
utils.decref(alignment, self.bytes, data_bytes); utils.decref(self.bytes, data_bytes, alignment);
return new_list; return new_list;
} }
@ -122,7 +122,7 @@ pub const RocList = extern struct {
.length = new_length, .length = new_length,
}; };
utils.decref(alignment, self.bytes, old_length * element_width); utils.decref(self.bytes, old_length * element_width, alignment);
return result; return result;
} }
@ -162,7 +162,7 @@ pub fn listReverse(list: RocList, alignment: u32, element_width: usize) callconv
@memcpy(target_ptr + (i * element_width), source_ptr + (last_position * element_width), element_width); @memcpy(target_ptr + (i * element_width), source_ptr + (last_position * element_width), element_width);
} }
utils.decref(alignment, list.bytes, size * element_width); utils.decref(list.bytes, size * element_width, alignment);
return output; return output;
} }
@ -383,7 +383,7 @@ pub fn listKeepIf(
if (kept == 0) { if (kept == 0) {
// if the output is empty, deallocate the space we made for the result // if the output is empty, deallocate the space we made for the result
utils.decref(alignment, output.bytes, size * element_width); utils.decref(output.bytes, size * element_width, alignment);
return RocList.empty(); return RocList.empty();
} else { } else {
output.length = kept; output.length = kept;
@ -493,7 +493,7 @@ pub fn listKeepResult(
utils.dealloc(temporary, alignment); utils.dealloc(temporary, alignment);
if (kept == 0) { if (kept == 0) {
utils.decref(alignment, output.bytes, size * after_width); utils.decref(output.bytes, size * after_width, alignment);
return RocList.empty(); return RocList.empty();
} else { } else {
output.length = kept; output.length = kept;
@ -750,7 +750,7 @@ pub fn listDrop(
@memcpy(target_ptr, source_ptr + drop_count * element_width, keep_count * element_width); @memcpy(target_ptr, source_ptr + drop_count * element_width, keep_count * element_width);
utils.decref(alignment, list.bytes, size * element_width); utils.decref(list.bytes, size * element_width, alignment);
return output; return output;
} else { } else {

View file

@ -81,7 +81,7 @@ pub const RocStr = extern struct {
pub fn deinit(self: RocStr) void { pub fn deinit(self: RocStr) void {
if (!self.isSmallStr() and !self.isEmpty()) { if (!self.isSmallStr() and !self.isEmpty()) {
utils.decref(RocStr.alignment, self.str_bytes, self.str_len); utils.decref(self.str_bytes, self.str_len, RocStr.alignment);
} }
} }
@ -1102,7 +1102,7 @@ fn fromUtf8(arg: RocList) FromUtf8Result {
// then decrement the input list // then decrement the input list
const data_bytes = arg.len(); const data_bytes = arg.len();
utils.decref(RocStr.alignment, arg.bytes, data_bytes); utils.decref(arg.bytes, data_bytes, RocStr.alignment);
return FromUtf8Result{ .is_ok = true, .string = string, .byte_index = 0, .problem_code = Utf8ByteProblem.InvalidStartByte }; return FromUtf8Result{ .is_ok = true, .string = string, .byte_index = 0, .problem_code = Utf8ByteProblem.InvalidStartByte };
} else { } else {
@ -1117,7 +1117,7 @@ fn fromUtf8(arg: RocList) FromUtf8Result {
// consume the input list // consume the input list
const data_bytes = arg.len(); const data_bytes = arg.len();
utils.decref(RocStr.alignment, arg.bytes, data_bytes); utils.decref(arg.bytes, data_bytes, RocStr.alignment);
return FromUtf8Result{ .is_ok = false, .string = RocStr.empty(), .byte_index = temp.index, .problem_code = temp.problem }; return FromUtf8Result{ .is_ok = false, .string = RocStr.empty(), .byte_index = temp.index, .problem_code = temp.problem };
} }

View file

@ -110,9 +110,9 @@ pub fn intWidth(width: IntWidth) anytype {
} }
pub fn decref( pub fn decref(
alignment: u32,
bytes_or_null: ?[*]u8, bytes_or_null: ?[*]u8,
data_bytes: usize, data_bytes: usize,
alignment: u32,
) void { ) void {
if (data_bytes == 0) { if (data_bytes == 0) {
return; return;