Fix a few std.sort.sort invocations

This commit is contained in:
Cassidy Dingenskirchen 2020-06-12 16:32:02 +02:00 committed by Andrew Kelley
parent 7d8fd45267
commit 57f1ed5325
5 changed files with 16 additions and 16 deletions

View File

@ -92,7 +92,7 @@ const BinaryElfOutput = struct {
}
}
sort.sort(*BinaryElfSegment, self.segments.span(), segmentSortCompare);
sort.sort(*BinaryElfSegment, self.segments.span(), {}, segmentSortCompare);
if (self.segments.items.len > 0) {
const firstSegment = self.segments.items[0];
@ -117,7 +117,7 @@ const BinaryElfOutput = struct {
}
}
sort.sort(*BinaryElfSection, self.sections.span(), sectionSortCompare);
sort.sort(*BinaryElfSection, self.sections.span(), {}, sectionSortCompare);
return self;
}
@ -131,7 +131,7 @@ const BinaryElfOutput = struct {
((shdr.sh_flags & elf.SHF_ALLOC) == elf.SHF_ALLOC);
}
fn segmentSortCompare(left: *BinaryElfSegment, right: *BinaryElfSegment) bool {
fn segmentSortCompare(context: void, left: *BinaryElfSegment, right: *BinaryElfSegment) bool {
if (left.physicalAddress < right.physicalAddress) {
return true;
}
@ -141,7 +141,7 @@ const BinaryElfOutput = struct {
return false;
}
fn sectionSortCompare(left: *BinaryElfSection, right: *BinaryElfSection) bool {
fn sectionSortCompare(context: void, left: *BinaryElfSection, right: *BinaryElfSection) bool {
return left.binaryOffset < right.binaryOffset;
}
};

View File

@ -145,8 +145,8 @@ test "std.meta.Child" {
/// Given a "memory span" type, returns the "element type".
pub fn Elem(comptime T: type) type {
switch (@typeInfo(T)) {
.Array, => |info| return info.child,
.Vector, => |info| return info.child,
.Array => |info| return info.child,
.Vector => |info| return info.child,
.Pointer => |info| switch (info.size) {
.One => switch (@typeInfo(info.child)) {
.Array => |array_info| return array_info.child,
@ -658,7 +658,7 @@ pub fn refAllDecls(comptime T: type) void {
/// Returns a slice of pointers to public declarations of a namespace.
pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const Decl {
const S = struct {
fn declNameLessThan(lhs: *const Decl, rhs: *const Decl) bool {
fn declNameLessThan(context: void, lhs: *const Decl, rhs: *const Decl) bool {
return mem.lessThan(u8, lhs.name, rhs.name);
}
};
@ -668,7 +668,7 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De
for (decls) |decl, i| {
array[i] = &@field(Namespace, decl.name);
}
std.sort.sort(*const Decl, &array, S.declNameLessThan);
std.sort.sort(*const Decl, &array, {}, S.declNameLessThan);
return &array;
}
}

View File

@ -242,7 +242,7 @@ const Contents = struct {
hash: []const u8,
is_generic: bool,
fn hitCountLessThan(lhs: *const Contents, rhs: *const Contents) bool {
fn hitCountLessThan(context: void, lhs: *const Contents, rhs: *const Contents) bool {
return lhs.hit_count < rhs.hit_count;
}
};
@ -414,7 +414,7 @@ pub fn main() !void {
try contents_list.append(contents);
}
}
std.sort.sort(*Contents, contents_list.span(), Contents.hitCountLessThan);
std.sort.sort(*Contents, contents_list.span(), {}, Contents.hitCountLessThan);
var best_contents = contents_list.popOrNull().?;
if (best_contents.hit_count > 1) {
// worth it to make it generic

View File

@ -352,7 +352,7 @@ pub fn main() anyerror!void {
}
// Some options have multiple matches. As an example, "-Wl,foo" matches both
// "W" and "Wl,". So we sort this list in order of descending priority.
std.sort.sort(*json.ObjectMap, all_objects.span(), objectLessThan);
std.sort.sort(*json.ObjectMap, all_objects.span(), {}, objectLessThan);
var stdout_bos = std.io.bufferedOutStream(std.io.getStdOut().outStream());
const stdout = stdout_bos.outStream();
@ -544,7 +544,7 @@ fn syntaxMatchesWithEql(syntax: Syntax) bool {
};
}
fn objectLessThan(a: *json.ObjectMap, b: *json.ObjectMap) bool {
fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool {
// Priority is determined by exact matches first, followed by prefix matches in descending
// length, with key as a final tiebreaker.
const a_syntax = objSyntax(a);

View File

@ -225,14 +225,14 @@ pub fn main() !void {
var list = std.ArrayList([]const u8).init(allocator);
var it = global_fn_set.iterator();
while (it.next()) |kv| try list.append(kv.key);
std.sort.sort([]const u8, list.span(), strCmpLessThan);
std.sort.sort([]const u8, list.span(), {}, strCmpLessThan);
break :blk list.span();
};
const global_ver_list = blk: {
var list = std.ArrayList([]const u8).init(allocator);
var it = global_ver_set.iterator();
while (it.next()) |kv| try list.append(kv.key);
std.sort.sort([]const u8, list.span(), versionLessThan);
std.sort.sort([]const u8, list.span(), {}, versionLessThan);
break :blk list.span();
};
{
@ -311,11 +311,11 @@ pub fn main() !void {
}
}
pub fn strCmpLessThan(a: []const u8, b: []const u8) bool {
pub fn strCmpLessThan(context: void, a: []const u8, b: []const u8) bool {
return std.mem.order(u8, a, b) == .lt;
}
pub fn versionLessThan(a: []const u8, b: []const u8) bool {
pub fn versionLessThan(context: void, a: []const u8, b: []const u8) bool {
const sep_chars = "GLIBC_.";
var a_tokens = std.mem.tokenize(a, sep_chars);
var b_tokens = std.mem.tokenize(b, sep_chars);