Commit 7a8c5049 authored by vogelheim's avatar vogelheim Committed by Commit bot

Remove unused code from DuplicateFinder.

BUG=v8:4947

Review-Url: https://codereview.chromium.org/2547493002
Cr-Commit-Position: refs/heads/master@{#41453}
parent 07eca01b
......@@ -4,83 +4,26 @@
#include "src/parsing/duplicate-finder.h"
#include "src/conversions.h"
#include "src/unicode-cache.h"
namespace v8 {
namespace internal {
int DuplicateFinder::AddOneByteSymbol(Vector<const uint8_t> key, int value) {
return AddSymbol(key, true, value);
bool DuplicateFinder::AddOneByteSymbol(Vector<const uint8_t> key) {
return AddSymbol(key, true);
}
int DuplicateFinder::AddTwoByteSymbol(Vector<const uint16_t> key, int value) {
return AddSymbol(Vector<const uint8_t>::cast(key), false, value);
bool DuplicateFinder::AddTwoByteSymbol(Vector<const uint16_t> key) {
return AddSymbol(Vector<const uint8_t>::cast(key), false);
}
int DuplicateFinder::AddSymbol(Vector<const uint8_t> key, bool is_one_byte,
int value) {
bool DuplicateFinder::AddSymbol(Vector<const uint8_t> key, bool is_one_byte) {
uint32_t hash = Hash(key, is_one_byte);
byte* encoding = BackupKey(key, is_one_byte);
base::HashMap::Entry* entry = map_.LookupOrInsert(encoding, hash);
int old_value = static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
entry->value =
reinterpret_cast<void*>(static_cast<intptr_t>(value | old_value));
entry->value = reinterpret_cast<void*>(1);
return old_value;
}
int DuplicateFinder::AddNumber(Vector<const uint8_t> key, int value) {
DCHECK(key.length() > 0);
// Quick check for already being in canonical form.
if (IsNumberCanonical(key)) {
return AddOneByteSymbol(key, value);
}
int flags = ALLOW_HEX | ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY;
double double_value = StringToDouble(unicode_constants_, key, flags, 0.0);
int length;
const char* string;
if (!std::isfinite(double_value)) {
string = "Infinity";
length = 8; // strlen("Infinity");
} else {
string = DoubleToCString(double_value,
Vector<char>(number_buffer_, kBufferSize));
length = StrLength(string);
}
return AddSymbol(
Vector<const byte>(reinterpret_cast<const byte*>(string), length), true,
value);
}
bool DuplicateFinder::IsNumberCanonical(Vector<const uint8_t> number) {
// Test for a safe approximation of number literals that are already
// in canonical form: max 15 digits, no leading zeroes, except an
// integer part that is a single zero, and no trailing zeros below
// the decimal point.
int pos = 0;
int length = number.length();
if (number.length() > 15) return false;
if (number[pos] == '0') {
pos++;
} else {
while (pos < length &&
static_cast<unsigned>(number[pos] - '0') <= ('9' - '0'))
pos++;
}
if (length == pos) return true;
if (number[pos] != '.') return false;
pos++;
bool invalid_last_digit = true;
while (pos < length) {
uint8_t digit = number[pos] - '0';
if (digit > '9' - '0') return false;
invalid_last_digit = (digit == 0);
pos++;
}
return !invalid_last_digit;
}
uint32_t DuplicateFinder::Hash(Vector<const uint8_t> key, bool is_one_byte) {
// Primitive hash function, almost identical to the one used
// for strings (except that it's seeded by the length and representation).
......
......@@ -11,25 +11,16 @@
namespace v8 {
namespace internal {
class UnicodeCache;
// DuplicateFinder discovers duplicate symbols.
class DuplicateFinder {
public:
explicit DuplicateFinder(UnicodeCache* constants)
: unicode_constants_(constants), backing_store_(16), map_(&Match) {}
DuplicateFinder() : backing_store_(16), map_(&Match) {}
int AddOneByteSymbol(Vector<const uint8_t> key, int value);
int AddTwoByteSymbol(Vector<const uint16_t> key, int value);
// Add a a number literal by converting it (if necessary)
// to the string that ToString(ToNumber(literal)) would generate.
// and then adding that string with AddOneByteSymbol.
// This string is the actual value used as key in an object literal,
// and the one that must be different from the other keys.
int AddNumber(Vector<const uint8_t> key, int value);
bool AddOneByteSymbol(Vector<const uint8_t> key);
bool AddTwoByteSymbol(Vector<const uint16_t> key);
private:
int AddSymbol(Vector<const uint8_t> key, bool is_one_byte, int value);
bool AddSymbol(Vector<const uint8_t> key, bool is_one_byte);
// Backs up the key and its length in the backing store.
// The backup is stored with a base 127 encoding of the
// length (plus a bit saying whether the string is one byte),
......@@ -40,22 +31,13 @@ class DuplicateFinder {
// for having the same base-127 encoded lengths and representation.
// and then having the same 'length' bytes following.
static bool Match(void* first, void* second);
// Creates a hash from a sequence of bytes.
static uint32_t Hash(Vector<const uint8_t> key, bool is_one_byte);
// Checks whether a string containing a JS number is its canonical
// form.
static bool IsNumberCanonical(Vector<const uint8_t> key);
// Size of buffer. Sufficient for using it to call DoubleToCString in
// from conversions.h.
static const int kBufferSize = 100;
UnicodeCache* unicode_constants_;
// Backing store used to store strings used as hashmap keys.
SequenceCollector<unsigned char> backing_store_;
base::CustomMatcherHashMap map_;
// Buffer used for string->number->canonical string conversions.
char number_buffer_[kBufferSize];
};
} // namespace internal
......
......@@ -1610,7 +1610,7 @@ ParserBase<Impl>::ParseAndClassifyIdentifier(bool* ok) {
}
if (classifier()->duplicate_finder() != nullptr &&
scanner()->FindSymbol(classifier()->duplicate_finder(), 1) != 0) {
scanner()->FindSymbol(classifier()->duplicate_finder())) {
classifier()->RecordDuplicateFormalParameterError(scanner()->location());
}
return name;
......@@ -2374,7 +2374,7 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker,
DCHECK(!*is_computed_name);
if (classifier()->duplicate_finder() != nullptr &&
scanner()->FindSymbol(classifier()->duplicate_finder(), 1) != 0) {
scanner()->FindSymbol(classifier()->duplicate_finder())) {
classifier()->RecordDuplicateFormalParameterError(
scanner()->location());
}
......
......@@ -3159,7 +3159,7 @@ ZoneList<Statement*>* Parser::ParseFunction(
FunctionState function_state(&function_state_, &scope_state_, function_scope);
DuplicateFinder duplicate_finder(scanner()->unicode_cache());
DuplicateFinder duplicate_finder;
ExpressionClassifier formals_classifier(this, &duplicate_finder);
if (IsGeneratorFunction(kind)) PrepareGeneratorVariables(&function_state);
......
......@@ -108,7 +108,7 @@ PreParser::PreParseResult PreParser::PreParseFunction(
PreParserFormalParameters formals(function_scope);
bool has_duplicate_parameters = false;
DuplicateFinder duplicate_finder(scanner()->unicode_cache());
DuplicateFinder duplicate_finder;
std::unique_ptr<ExpressionClassifier> formals_classifier;
// Parse non-arrow function parameters. For arrow functions, the parameters
......@@ -198,7 +198,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
DeclarationScope* function_scope = NewFunctionScope(kind);
function_scope->SetLanguageMode(language_mode);
FunctionState function_state(&function_state_, &scope_state_, function_scope);
DuplicateFinder duplicate_finder(scanner()->unicode_cache());
DuplicateFinder duplicate_finder;
ExpressionClassifier formals_classifier(this, &duplicate_finder);
GetNextFunctionLiteralId();
......
......@@ -1600,14 +1600,13 @@ bool Scanner::ContainsDot() {
return std::find(str.begin(), str.end(), '.') != str.end();
}
int Scanner::FindSymbol(DuplicateFinder* finder, int value) {
bool Scanner::FindSymbol(DuplicateFinder* finder) {
// TODO(vogelheim): Move this logic into the calling class; this can be fully
// implemented using the public interface.
if (is_literal_one_byte()) {
return finder->AddOneByteSymbol(literal_one_byte_string(), value);
return finder->AddOneByteSymbol(literal_one_byte_string());
}
return finder->AddTwoByteSymbol(literal_two_byte_string(), value);
return finder->AddTwoByteSymbol(literal_two_byte_string());
}
void Scanner::SeekNext(size_t position) {
......
......@@ -268,7 +268,7 @@ class Scanner {
return false;
}
int FindSymbol(DuplicateFinder* finder, int value);
bool FindSymbol(DuplicateFinder* finder);
UnicodeCache* unicode_cache() { return unicode_cache_; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment