Commit 74543fed authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

Use size_t for Vector<T> size.

Conf. c++ coding guide (https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md#Types),
we may use size_t for vector indices, etc.

Bug: 
Change-Id: I578fb4199c061b006d03e1cc68e745868b40c227
Reviewed-on: https://chromium-review.googlesource.com/503590
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45267}
parent f61facfd
......@@ -7667,8 +7667,7 @@ MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize(
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::MaybeHandle<i::FixedArray> maybe_compiled_part =
i::WasmCompiledModuleSerializer::DeserializeWasmModule(
i_isolate, &sc,
{wire_bytes.first, static_cast<int>(wire_bytes.second)});
i_isolate, &sc, {wire_bytes.first, wire_bytes.second});
i::Handle<i::FixedArray> compiled_part;
if (!maybe_compiled_part.ToHandle(&compiled_part)) {
return MaybeLocal<WasmCompiledModule>();
......
......@@ -3816,16 +3816,17 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
}
if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
const char* function_name = nullptr;
int function_name_size = 0;
size_t function_name_size = 0;
if (!import_name.is_null()) {
Handle<String> handle = import_name.ToHandleChecked();
function_name = handle->ToCString().get();
function_name_size = handle->length();
function_name_size = static_cast<size_t>(handle->length());
}
RecordFunctionCompilation(
CodeEventListener::FUNCTION_TAG, isolate, code, "wasm-to-js", index,
{module_name->ToCString().get(), module_name->length()},
{function_name, function_name_size});
RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, isolate, code,
"wasm-to-js", index,
{module_name->ToCString().get(),
static_cast<size_t>(module_name->length())},
{function_name, function_name_size});
}
return code;
......
......@@ -20,8 +20,9 @@ template <typename T>
class Vector {
public:
Vector() : start_(NULL), length_(0) {}
Vector(T* data, int length) : start_(data), length_(length) {
DCHECK(length == 0 || (length > 0 && data != NULL));
Vector(T* data, size_t length) : start_(data), length_(length) {
DCHECK(length == 0 || data != NULL);
}
template <int N>
......@@ -33,15 +34,20 @@ class Vector {
// Returns a vector using the same backing storage as this one,
// spanning from and including 'from', to but not including 'to'.
Vector<T> SubVector(int from, int to) const {
DCHECK_LE(0, from);
Vector<T> SubVector(size_t from, size_t to) const {
DCHECK_LE(from, to);
DCHECK_LE(to, length_);
return Vector<T>(start() + from, to - from);
}
// Returns the length of the vector.
int length() const { return length_; }
int length() const {
DCHECK(length_ <= static_cast<size_t>(std::numeric_limits<int>::max()));
return static_cast<int>(length_);
}
// Returns the length of the vector as a size_t.
size_t size() const { return length_; }
// Returns whether or not the vector is empty.
bool is_empty() const { return length_ == 0; }
......@@ -50,13 +56,12 @@ class Vector {
T* start() const { return start_; }
// Access individual vector elements - checks bounds in debug mode.
T& operator[](int index) const {
DCHECK_LE(0, index);
T& operator[](size_t index) const {
DCHECK_LT(index, length_);
return start_[index];
}
const T& at(int index) const { return operator[](index); }
const T& at(size_t index) const { return operator[](index); }
T& first() { return start_[0]; }
......@@ -69,7 +74,7 @@ class Vector {
// Returns a clone of this vector with a new backing store.
Vector<T> Clone() const {
T* result = NewArray<T>(length_);
for (int i = 0; i < length_; i++) result[i] = start_[i];
for (size_t i = 0; i < length_; i++) result[i] = start_[i];
return Vector<T>(result, length_);
}
......@@ -101,7 +106,7 @@ class Vector {
void StableSort() { std::stable_sort(start(), start() + length()); }
void Truncate(int length) {
void Truncate(size_t length) {
DCHECK(length <= length_);
length_ = length;
}
......@@ -114,8 +119,8 @@ class Vector {
length_ = 0;
}
inline Vector<T> operator+(int offset) {
DCHECK(offset < length_);
inline Vector<T> operator+(size_t offset) {
DCHECK_LT(offset, length_);
return Vector<T>(start_ + offset, length_ - offset);
}
......@@ -134,7 +139,7 @@ class Vector {
bool operator==(const Vector<T>& other) const {
if (length_ != other.length_) return false;
if (start_ == other.start_) return true;
for (int i = 0; i < length_; ++i) {
for (size_t i = 0; i < length_; ++i) {
if (start_[i] != other.start_[i]) {
return false;
}
......@@ -147,7 +152,7 @@ class Vector {
private:
T* start_;
int length_;
size_t length_;
template <typename CookedComparer>
class RawComparer {
......
......@@ -144,8 +144,8 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
script->set_type(Script::TYPE_WASM);
int hash = StringHasher::HashSequentialString(
reinterpret_cast<const char*>(wire_bytes.start()), wire_bytes.length(),
kZeroHashSeed);
reinterpret_cast<const char*>(wire_bytes.start()),
static_cast<int>(wire_bytes.length()), kZeroHashSeed);
const int kBufferSize = 32;
char buffer[kBufferSize];
......@@ -2619,7 +2619,7 @@ class AsyncCompileJob {
// finished.
public:
explicit AsyncCompileJob(Isolate* isolate, std::unique_ptr<byte[]> bytes_copy,
int length, Handle<Context> context,
size_t length, Handle<Context> context,
Handle<JSPromise> promise)
: isolate_(isolate),
bytes_copy_(std::move(bytes_copy)),
......
......@@ -294,7 +294,7 @@ struct V8_EXPORT_PRIVATE ModuleWireBytes {
const byte* start() const { return module_bytes_.start(); }
const byte* end() const { return module_bytes_.end(); }
int length() const { return module_bytes_.length(); }
size_t length() const { return module_bytes_.length(); }
private:
const Vector<const byte> module_bytes_;
......
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