Commit 2f1df8a3 authored by clemensh's avatar clemensh Committed by Commit bot

Refactoring to use ArrayVector where applicable

It's more readable than the construction
Vector<T>(buffer, arraysize(buffer)).
All those places are now replaced by ArrayVector(buffer).

R=titzer@chromium.org, jarin@chromium.org, rossberg@chromium.org

Review-Url: https://codereview.chromium.org/1916393002
Cr-Commit-Position: refs/heads/master@{#35843}
parent cd3a5ee9
......@@ -3113,8 +3113,7 @@ BUILTIN(DateConstructor) {
HandleScope scope(isolate);
double const time_val = JSDate::CurrentTimeValue(isolate);
char buffer[128];
Vector<char> str(buffer, arraysize(buffer));
ToDateString(time_val, str, isolate->date_cache());
ToDateString(time_val, ArrayVector(buffer), isolate->date_cache());
Handle<String> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
......@@ -3697,8 +3696,8 @@ BUILTIN(DatePrototypeToDateString) {
HandleScope scope(isolate);
CHECK_RECEIVER(JSDate, date, "Date.prototype.toDateString");
char buffer[128];
Vector<char> str(buffer, arraysize(buffer));
ToDateString(date->value()->Number(), str, isolate->date_cache(), kDateOnly);
ToDateString(date->value()->Number(), ArrayVector(buffer),
isolate->date_cache(), kDateOnly);
Handle<String> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
......@@ -3721,18 +3720,17 @@ BUILTIN(DatePrototypeToISOString) {
isolate->date_cache()->BreakDownTime(time_ms, &year, &month, &day, &weekday,
&hour, &min, &sec, &ms);
char buffer[128];
Vector<char> str(buffer, arraysize(buffer));
if (year >= 0 && year <= 9999) {
SNPrintF(str, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, month + 1, day,
hour, min, sec, ms);
SNPrintF(ArrayVector(buffer), "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", year,
month + 1, day, hour, min, sec, ms);
} else if (year < 0) {
SNPrintF(str, "-%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", -year, month + 1, day,
hour, min, sec, ms);
SNPrintF(ArrayVector(buffer), "-%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", -year,
month + 1, day, hour, min, sec, ms);
} else {
SNPrintF(str, "+%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", year, month + 1, day,
hour, min, sec, ms);
SNPrintF(ArrayVector(buffer), "+%06d-%02d-%02dT%02d:%02d:%02d.%03dZ", year,
month + 1, day, hour, min, sec, ms);
}
return *isolate->factory()->NewStringFromAsciiChecked(str.start());
return *isolate->factory()->NewStringFromAsciiChecked(buffer);
}
......@@ -3741,8 +3739,8 @@ BUILTIN(DatePrototypeToString) {
HandleScope scope(isolate);
CHECK_RECEIVER(JSDate, date, "Date.prototype.toString");
char buffer[128];
Vector<char> str(buffer, arraysize(buffer));
ToDateString(date->value()->Number(), str, isolate->date_cache());
ToDateString(date->value()->Number(), ArrayVector(buffer),
isolate->date_cache());
Handle<String> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
......@@ -3756,8 +3754,8 @@ BUILTIN(DatePrototypeToTimeString) {
HandleScope scope(isolate);
CHECK_RECEIVER(JSDate, date, "Date.prototype.toTimeString");
char buffer[128];
Vector<char> str(buffer, arraysize(buffer));
ToDateString(date->value()->Number(), str, isolate->date_cache(), kTimeOnly);
ToDateString(date->value()->Number(), ArrayVector(buffer),
isolate->date_cache(), kTimeOnly);
Handle<String> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
......@@ -3775,14 +3773,14 @@ BUILTIN(DatePrototypeToUTCString) {
return *isolate->factory()->NewStringFromAsciiChecked("Invalid Date");
}
char buffer[128];
Vector<char> str(buffer, arraysize(buffer));
int64_t time_ms = static_cast<int64_t>(time_val);
int year, month, day, weekday, hour, min, sec, ms;
isolate->date_cache()->BreakDownTime(time_ms, &year, &month, &day, &weekday,
&hour, &min, &sec, &ms);
SNPrintF(str, "%s, %02d %s %4d %02d:%02d:%02d GMT", kShortWeekDays[weekday],
day, kShortMonths[month], year, hour, min, sec);
return *isolate->factory()->NewStringFromAsciiChecked(str.start());
SNPrintF(ArrayVector(buffer), "%s, %02d %s %4d %02d:%02d:%02d GMT",
kShortWeekDays[weekday], day, kShortMonths[month], year, hour, min,
sec);
return *isolate->factory()->NewStringFromAsciiChecked(buffer);
}
......
......@@ -1637,9 +1637,9 @@ HValue* CodeStubGraphBuilderBase::BuildToString(HValue* input, bool convert) {
// Convert the primitive to a string value.
ToStringStub stub(isolate());
HValue* values[] = {context(), Pop()};
Push(AddUncasted<HCallWithDescriptor>(
Add<HConstant>(stub.GetCode()), 0, stub.GetCallInterfaceDescriptor(),
Vector<HValue*>(values, arraysize(values))));
Push(AddUncasted<HCallWithDescriptor>(Add<HConstant>(stub.GetCode()), 0,
stub.GetCallInterfaceDescriptor(),
ArrayVector(values)));
}
if_inputisstring.End();
}
......
......@@ -2227,9 +2227,8 @@ HValue* HGraphBuilder::BuildToNumber(HValue* input) {
Callable callable = CodeFactory::ToNumber(isolate());
HValue* stub = Add<HConstant>(callable.code());
HValue* values[] = {context(), input};
HCallWithDescriptor* instr =
Add<HCallWithDescriptor>(stub, 0, callable.descriptor(),
Vector<HValue*>(values, arraysize(values)));
HCallWithDescriptor* instr = Add<HCallWithDescriptor>(
stub, 0, callable.descriptor(), ArrayVector(values));
instr->set_type(HType::TaggedNumber());
return instr;
}
......@@ -5670,8 +5669,8 @@ void HOptimizedGraphBuilder::VisitFunctionLiteral(FunctionLiteral* expr) {
FastNewClosureDescriptor descriptor(isolate());
HValue* values[] = {context(), shared_info_value};
HConstant* stub_value = Add<HConstant>(stub.GetCode());
instr = New<HCallWithDescriptor>(
stub_value, 0, descriptor, Vector<HValue*>(values, arraysize(values)));
instr = New<HCallWithDescriptor>(stub_value, 0, descriptor,
ArrayVector(values));
} else {
Add<HPushArguments>(shared_info_value);
Runtime::FunctionId function_id =
......@@ -5949,9 +5948,8 @@ void HOptimizedGraphBuilder::VisitRegExpLiteral(RegExpLiteral* expr) {
context(), AddThisFunction(), Add<HConstant>(expr->literal_index()),
Add<HConstant>(expr->pattern()), Add<HConstant>(expr->flags())};
HConstant* stub_value = Add<HConstant>(callable.code());
HInstruction* instr =
New<HCallWithDescriptor>(stub_value, 0, callable.descriptor(),
Vector<HValue*>(values, arraysize(values)));
HInstruction* instr = New<HCallWithDescriptor>(
stub_value, 0, callable.descriptor(), ArrayVector(values));
return ast_context()->ReturnInstruction(instr, expr->id());
}
......@@ -8173,7 +8171,7 @@ HInstruction* HOptimizedGraphBuilder::NewCallFunction(
HConstant* stub = Add<HConstant>(callable.code());
return New<HCallWithDescriptor>(stub, argument_count, callable.descriptor(),
Vector<HValue*>(op_vals, arraysize(op_vals)),
ArrayVector(op_vals),
syntactic_tail_call_mode);
}
......@@ -8198,7 +8196,7 @@ HInstruction* HOptimizedGraphBuilder::NewCallFunctionViaIC(
HConstant* stub = Add<HConstant>(callable.code());
return New<HCallWithDescriptor>(stub, argument_count, callable.descriptor(),
Vector<HValue*>(op_vals, arraysize(op_vals)),
ArrayVector(op_vals),
syntactic_tail_call_mode);
}
......@@ -10237,9 +10235,8 @@ void HOptimizedGraphBuilder::VisitCallNew(CallNew* expr) {
Callable callable = CodeFactory::Construct(isolate());
HConstant* stub = Add<HConstant>(callable.code());
PushArgumentsFromEnvironment(argument_count);
HInstruction* construct =
New<HCallWithDescriptor>(stub, argument_count, callable.descriptor(),
Vector<HValue*>(op_vals, arraysize(op_vals)));
HInstruction* construct = New<HCallWithDescriptor>(
stub, argument_count, callable.descriptor(), ArrayVector(op_vals));
return ast_context()->ReturnInstruction(construct, expr->id());
}
......@@ -11306,13 +11303,12 @@ HValue* HGraphBuilder::BuildBinaryOperation(Token::Value op, HValue* left,
// operation in optimized code, which is more expensive, than a stub call.
if (graph()->info()->IsStub() && is_non_primitive) {
HValue* values[] = {context(), left, right};
#define GET_STUB(Name) \
do { \
Callable callable = CodeFactory::Name(isolate()); \
HValue* stub = Add<HConstant>(callable.code()); \
instr = AddUncasted<HCallWithDescriptor>( \
stub, 0, callable.descriptor(), \
Vector<HValue*>(values, arraysize(values))); \
#define GET_STUB(Name) \
do { \
Callable callable = CodeFactory::Name(isolate()); \
HValue* stub = Add<HConstant>(callable.code()); \
instr = AddUncasted<HCallWithDescriptor>(stub, 0, callable.descriptor(), \
ArrayVector(values)); \
} while (false)
switch (op) {
......@@ -12445,9 +12441,8 @@ void HOptimizedGraphBuilder::GenerateToInteger(CallRuntime* call) {
Callable callable = CodeFactory::ToInteger(isolate());
HValue* stub = Add<HConstant>(callable.code());
HValue* values[] = {context(), input};
HInstruction* result =
New<HCallWithDescriptor>(stub, 0, callable.descriptor(),
Vector<HValue*>(values, arraysize(values)));
HInstruction* result = New<HCallWithDescriptor>(
stub, 0, callable.descriptor(), ArrayVector(values));
return ast_context()->ReturnInstruction(result, call->id());
}
}
......@@ -12469,9 +12464,8 @@ void HOptimizedGraphBuilder::GenerateToName(CallRuntime* call) {
Callable callable = CodeFactory::ToName(isolate());
HValue* stub = Add<HConstant>(callable.code());
HValue* values[] = {context(), input};
HInstruction* result =
New<HCallWithDescriptor>(stub, 0, callable.descriptor(),
Vector<HValue*>(values, arraysize(values)));
HInstruction* result = New<HCallWithDescriptor>(
stub, 0, callable.descriptor(), ArrayVector(values));
return ast_context()->ReturnInstruction(result, call->id());
}
}
......@@ -12496,9 +12490,8 @@ void HOptimizedGraphBuilder::GenerateToString(CallRuntime* call) {
Callable callable = CodeFactory::ToString(isolate());
HValue* stub = Add<HConstant>(callable.code());
HValue* values[] = {context(), input};
HInstruction* result =
New<HCallWithDescriptor>(stub, 0, callable.descriptor(),
Vector<HValue*>(values, arraysize(values)));
HInstruction* result = New<HCallWithDescriptor>(
stub, 0, callable.descriptor(), ArrayVector(values));
return ast_context()->ReturnInstruction(result, call->id());
}
}
......@@ -12511,9 +12504,8 @@ void HOptimizedGraphBuilder::GenerateToLength(CallRuntime* call) {
HValue* input = Pop();
HValue* stub = Add<HConstant>(callable.code());
HValue* values[] = {context(), input};
HInstruction* result =
New<HCallWithDescriptor>(stub, 0, callable.descriptor(),
Vector<HValue*>(values, arraysize(values)));
HInstruction* result = New<HCallWithDescriptor>(
stub, 0, callable.descriptor(), ArrayVector(values));
return ast_context()->ReturnInstruction(result, call->id());
}
......@@ -12686,9 +12678,9 @@ void HOptimizedGraphBuilder::GenerateSubString(CallRuntime* call) {
Callable callable = CodeFactory::SubString(isolate());
HValue* stub = Add<HConstant>(callable.code());
HValue* values[] = {context()};
HInstruction* result = New<HCallWithDescriptor>(
stub, call->arguments()->length(), callable.descriptor(),
Vector<HValue*>(values, arraysize(values)));
HInstruction* result =
New<HCallWithDescriptor>(stub, call->arguments()->length(),
callable.descriptor(), ArrayVector(values));
result->set_type(HType::String());
return ast_context()->ReturnInstruction(result, call->id());
}
......@@ -12701,8 +12693,8 @@ void HOptimizedGraphBuilder::GenerateNewObject(CallRuntime* call) {
FastNewObjectDescriptor descriptor(isolate());
HValue* values[] = {context(), Pop(), Pop()};
HConstant* stub_value = Add<HConstant>(stub.GetCode());
HInstruction* result = New<HCallWithDescriptor>(
stub_value, 0, descriptor, Vector<HValue*>(values, arraysize(values)));
HInstruction* result =
New<HCallWithDescriptor>(stub_value, 0, descriptor, ArrayVector(values));
return ast_context()->ReturnInstruction(result, call->id());
}
......@@ -12714,9 +12706,9 @@ void HOptimizedGraphBuilder::GenerateRegExpExec(CallRuntime* call) {
Callable callable = CodeFactory::RegExpExec(isolate());
HValue* stub = Add<HConstant>(callable.code());
HValue* values[] = {context()};
HInstruction* result = New<HCallWithDescriptor>(
stub, call->arguments()->length(), callable.descriptor(),
Vector<HValue*>(values, arraysize(values)));
HInstruction* result =
New<HCallWithDescriptor>(stub, call->arguments()->length(),
callable.descriptor(), ArrayVector(values));
return ast_context()->ReturnInstruction(result, call->id());
}
......@@ -12843,9 +12835,9 @@ void HOptimizedGraphBuilder::GenerateCall(CallRuntime* call) {
HValue* target = Pop();
HValue* values[] = {context(), target,
Add<HConstant>(call->arguments()->length() - 2)};
HInstruction* result = New<HCallWithDescriptor>(
trampoline, call->arguments()->length() - 1, descriptor,
Vector<HValue*>(values, arraysize(values)));
HInstruction* result =
New<HCallWithDescriptor>(trampoline, call->arguments()->length() - 1,
descriptor, ArrayVector(values));
return ast_context()->ReturnInstruction(result, call->id());
}
......
......@@ -602,8 +602,7 @@ const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) {
const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) {
double double_value = parser_->scanner()->DoubleValue();
char array[100];
const char* string =
DoubleToCString(double_value, Vector<char>(array, arraysize(array)));
const char* string = DoubleToCString(double_value, ArrayVector(array));
return parser_->ast_value_factory()->GetOneByteString(string);
}
......
......@@ -461,8 +461,7 @@ static const v8::CpuProfileNode* GetChild(v8::Local<v8::Context> context,
const v8::CpuProfileNode* result = FindChild(context, node, name);
if (!result) {
char buffer[100];
i::SNPrintF(Vector<char>(buffer, arraysize(buffer)),
"Failed to GetChild: %s", name);
i::SNPrintF(i::ArrayVector(buffer), "Failed to GetChild: %s", name);
FATAL(buffer);
}
return result;
......
......@@ -44,6 +44,7 @@ using i::AllocationTraceNode;
using i::AllocationTraceTree;
using i::AllocationTracker;
using i::HashMap;
using i::ArrayVector;
using i::Vector;
namespace {
......@@ -2513,8 +2514,7 @@ TEST(ArrayGrowLeftTrim) {
// Print for better diagnostics in case of failure.
tracker->trace_tree()->Print(tracker);
AllocationTraceNode* node =
FindNode(tracker, Vector<const char*>(names, arraysize(names)));
AllocationTraceNode* node = FindNode(tracker, ArrayVector(names));
CHECK(node);
CHECK_GE(node->allocation_count(), 2u);
CHECK_GE(node->allocation_size(), 4u * 5u);
......@@ -2540,8 +2540,7 @@ TEST(TrackHeapAllocations) {
tracker->trace_tree()->Print(tracker);
const char* names[] = {"", "start", "f_0_0", "f_0_1", "f_0_2"};
AllocationTraceNode* node =
FindNode(tracker, Vector<const char*>(names, arraysize(names)));
AllocationTraceNode* node = FindNode(tracker, ArrayVector(names));
CHECK(node);
CHECK_GE(node->allocation_count(), 100u);
CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
......@@ -2590,8 +2589,7 @@ TEST(TrackBumpPointerAllocations) {
// Print for better diagnostics in case of failure.
tracker->trace_tree()->Print(tracker);
AllocationTraceNode* node =
FindNode(tracker, Vector<const char*>(names, arraysize(names)));
AllocationTraceNode* node = FindNode(tracker, ArrayVector(names));
CHECK(node);
CHECK_GE(node->allocation_count(), 100u);
CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
......@@ -2616,8 +2614,7 @@ TEST(TrackBumpPointerAllocations) {
// Print for better diagnostics in case of failure.
tracker->trace_tree()->Print(tracker);
AllocationTraceNode* node =
FindNode(tracker, Vector<const char*>(names, arraysize(names)));
AllocationTraceNode* node = FindNode(tracker, ArrayVector(names));
CHECK(node);
CHECK_LT(node->allocation_count(), 100u);
......@@ -2646,8 +2643,7 @@ TEST(TrackV8ApiAllocation) {
// Print for better diagnostics in case of failure.
tracker->trace_tree()->Print(tracker);
AllocationTraceNode* node =
FindNode(tracker, Vector<const char*>(names, arraysize(names)));
AllocationTraceNode* node = FindNode(tracker, ArrayVector(names));
CHECK(node);
CHECK_GE(node->allocation_count(), 2u);
CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
......@@ -2922,8 +2918,7 @@ TEST(SamplingHeapProfiler) {
CHECK(!profile.is_empty());
const char* names[] = {"", "foo", "bar"};
auto node_bar = FindAllocationProfileNode(
*profile, Vector<const char*>(names, arraysize(names)));
auto node_bar = FindAllocationProfileNode(*profile, ArrayVector(names));
CHECK(node_bar);
// Count the number of allocations we sampled from bar.
......@@ -2950,8 +2945,7 @@ TEST(SamplingHeapProfiler) {
CHECK(!profile.is_empty());
const char* names[] = {"", "foo", "bar"};
auto node_bar = FindAllocationProfileNode(
*profile, Vector<const char*>(names, arraysize(names)));
auto node_bar = FindAllocationProfileNode(*profile, ArrayVector(names));
CHECK(node_bar);
// Count the number of allocations we sampled from bar.
......@@ -2985,13 +2979,11 @@ TEST(SamplingHeapProfiler) {
CHECK(!profile.is_empty());
const char* names1[] = {"", "start", "f_0_0", "f_0_1", "f_0_2"};
auto node1 = FindAllocationProfileNode(
*profile, Vector<const char*>(names1, arraysize(names1)));
auto node1 = FindAllocationProfileNode(*profile, ArrayVector(names1));
CHECK(node1);
const char* names2[] = {"", "generateFunctions"};
auto node2 = FindAllocationProfileNode(
*profile, Vector<const char*>(names2, arraysize(names2)));
auto node2 = FindAllocationProfileNode(*profile, ArrayVector(names2));
CHECK(node2);
heap_profiler->StopSamplingHeapProfiler();
......@@ -3034,8 +3026,7 @@ TEST(SamplingHeapProfilerApiAllocation) {
heap_profiler->GetAllocationProfile());
CHECK(!profile.is_empty());
const char* names[] = {"(V8 API)"};
auto node = FindAllocationProfileNode(
*profile, Vector<const char*>(names, arraysize(names)));
auto node = FindAllocationProfileNode(*profile, ArrayVector(names));
CHECK(node);
heap_profiler->StopSamplingHeapProfiler();
......
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