Skip to content

Commit

Permalink
std.sort: Remove key argument from binary-search-like functions (#20927)
Browse files Browse the repository at this point in the history
closes #20110
  • Loading branch information
Fri3dNstuff authored Aug 4, 2024
1 parent ea84753 commit a655c15
Show file tree
Hide file tree
Showing 3 changed files with 303 additions and 291 deletions.
7 changes: 3 additions & 4 deletions lib/compiler/aro/aro/Preprocessor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,13 @@ fn clearBuffers(pp: *Preprocessor) void {

pub fn expansionSlice(pp: *Preprocessor, tok: Tree.TokenIndex) []Source.Location {
const S = struct {
fn order_token_index(context: void, lhs: Tree.TokenIndex, rhs: Tree.TokenIndex) std.math.Order {
_ = context;
return std.math.order(lhs, rhs);
fn orderTokenIndex(context: Tree.TokenIndex, item: Tree.TokenIndex) std.math.Order {
return std.math.order(item, context);
}
};

const indices = pp.expansion_entries.items(.idx);
const idx = std.sort.binarySearch(Tree.TokenIndex, tok, indices, {}, S.order_token_index) orelse return &.{};
const idx = std.sort.binarySearch(Tree.TokenIndex, indices, tok, S.orderTokenIndex) orelse return &.{};
const locs = pp.expansion_entries.items(.locs)[idx];
var i: usize = 0;
while (locs[i].id != .unused) : (i += 1) {}
Expand Down
10 changes: 5 additions & 5 deletions lib/std/debug/SelfInfo.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1842,14 +1842,14 @@ pub fn unwindFrameDwarf(
&fde,
);
} else {
const index = std.sort.binarySearch(Dwarf.FrameDescriptionEntry, context.pc, di.fde_list.items, {}, struct {
pub fn compareFn(_: void, pc: usize, mid_item: Dwarf.FrameDescriptionEntry) std.math.Order {
if (pc < mid_item.pc_begin) return .lt;
const index = std.sort.binarySearch(Dwarf.FrameDescriptionEntry, di.fde_list.items, context.pc, struct {
pub fn compareFn(pc: usize, item: Dwarf.FrameDescriptionEntry) std.math.Order {
if (pc < item.pc_begin) return .gt;

const range_end = mid_item.pc_begin + mid_item.pc_range;
const range_end = item.pc_begin + item.pc_range;
if (pc < range_end) return .eq;

return .gt;
return .lt;
}
}.compareFn);

Expand Down
Loading

0 comments on commit a655c15

Please sign in to comment.