[turbofan] Use binary search in handler table lookup.
R=clemensb@chromium.org Change-Id: I38c851f258b49de75f538a9b893ab24b7a4d0586 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1883894 Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#64611}
This commit is contained in:
parent
f5fb0e740b
commit
30ec6a8937
@ -4,8 +4,10 @@
|
||||
|
||||
#include "src/codegen/handler-table.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
|
||||
#include "src/base/iterator.h"
|
||||
#include "src/codegen/assembler-inl.h"
|
||||
#include "src/objects/code-inl.h"
|
||||
#include "src/objects/objects-inl.h"
|
||||
@ -187,15 +189,35 @@ int HandlerTable::LookupRange(int pc_offset, int* data_out,
|
||||
return innermost_handler;
|
||||
}
|
||||
|
||||
// TODO(turbofan): Make sure table is sorted and use binary search.
|
||||
int HandlerTable::LookupReturn(int pc_offset) {
|
||||
for (int i = 0; i < NumberOfReturnEntries(); ++i) {
|
||||
int return_offset = GetReturnOffset(i);
|
||||
if (pc_offset == return_offset) {
|
||||
return GetReturnHandler(i);
|
||||
// We only implement the methods needed by the standard libraries we care
|
||||
// about. This is not technically a full random access iterator by the spec.
|
||||
struct Iterator : base::iterator<std::random_access_iterator_tag, int> {
|
||||
Iterator(HandlerTable* tbl, int idx) : table(tbl), index(idx) {}
|
||||
value_type operator*() const { return table->GetReturnOffset(index); }
|
||||
bool operator!=(const Iterator& other) const { return !(*this == other); }
|
||||
bool operator==(const Iterator& other) const {
|
||||
return index == other.index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
Iterator& operator++() {
|
||||
index++;
|
||||
return *this;
|
||||
}
|
||||
Iterator& operator+=(difference_type offset) {
|
||||
index += offset;
|
||||
return *this;
|
||||
}
|
||||
difference_type operator-(const Iterator& other) const {
|
||||
return index - other.index;
|
||||
}
|
||||
HandlerTable* table;
|
||||
int index;
|
||||
};
|
||||
Iterator begin{this, 0}, end{this, NumberOfReturnEntries()};
|
||||
SLOW_DCHECK(std::is_sorted(begin, end)); // Must be sorted.
|
||||
Iterator result = std::lower_bound(begin, end, pc_offset);
|
||||
bool exact_match = result != end && *result == pc_offset;
|
||||
return exact_match ? GetReturnHandler(result.index) : -1;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DISASSEMBLER
|
||||
|
Loading…
Reference in New Issue
Block a user