Commit d6c01d5f authored by Simon Zünd's avatar Simon Zünd Committed by V8 LUCI CQ

[inspector] Avoid unnecessary string copy when scheduling async tasks

R=bmeurer@chromium.org

Bug: chromium:1267427
Change-Id: Ibee0fb62fda5f834b1866e2b6ae17bebca34f4ba
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3317425
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78267}
parent df64feca
......@@ -71,6 +71,10 @@ String16 toProtocolString(v8::Isolate*, v8::Local<v8::String>);
String16 toProtocolStringWithTypeCheck(v8::Isolate*, v8::Local<v8::Value>);
String16 toString16(const StringView&);
StringView toStringView(const String16&);
template <size_t N>
StringView toStringView(const char* str[N]) {
return StringView(reinterpret_cast<const uint8_t*>(str), N);
}
bool stringViewStartsWith(const StringView&, const char*);
// Creates a string buffer instance which owns |str|, a 16 bit string.
......
......@@ -656,15 +656,15 @@ void V8Debugger::AsyncEventOccurred(v8::debug::DebugAsyncActionType type,
void* task = reinterpret_cast<void*>(id * 2 + 1);
switch (type) {
case v8::debug::kDebugPromiseThen:
asyncTaskScheduledForStack("Promise.then", task, false);
asyncTaskScheduledForStack(toStringView("Promise.then"), task, false);
if (!isBlackboxed) asyncTaskCandidateForStepping(task);
break;
case v8::debug::kDebugPromiseCatch:
asyncTaskScheduledForStack("Promise.catch", task, false);
asyncTaskScheduledForStack(toStringView("Promise.catch"), task, false);
if (!isBlackboxed) asyncTaskCandidateForStepping(task);
break;
case v8::debug::kDebugPromiseFinally:
asyncTaskScheduledForStack("Promise.finally", task, false);
asyncTaskScheduledForStack(toStringView("Promise.finally"), task, false);
if (!isBlackboxed) asyncTaskCandidateForStepping(task);
break;
case v8::debug::kDebugWillHandle:
......@@ -677,7 +677,7 @@ void V8Debugger::AsyncEventOccurred(v8::debug::DebugAsyncActionType type,
break;
case v8::debug::kAsyncFunctionSuspended: {
if (m_asyncTaskStacks.find(task) == m_asyncTaskStacks.end()) {
asyncTaskScheduledForStack("await", task, true, true);
asyncTaskScheduledForStack(toStringView("await"), task, true, true);
}
auto stackIt = m_asyncTaskStacks.find(task);
if (stackIt != m_asyncTaskStacks.end() && !stackIt->second.expired()) {
......@@ -976,7 +976,7 @@ void V8Debugger::externalAsyncTaskFinished(const V8StackTraceId& parent) {
void V8Debugger::asyncTaskScheduled(const StringView& taskName, void* task,
bool recurring) {
asyncTaskScheduledForStack(toString16(taskName), task, recurring);
asyncTaskScheduledForStack(taskName, task, recurring);
asyncTaskCandidateForStepping(task);
}
......@@ -995,13 +995,13 @@ void V8Debugger::asyncTaskFinished(void* task) {
asyncTaskFinishedForStack(task);
}
void V8Debugger::asyncTaskScheduledForStack(const String16& taskName,
void V8Debugger::asyncTaskScheduledForStack(const StringView& taskName,
void* task, bool recurring,
bool skipTopFrame) {
if (!m_maxAsyncCallStackDepth) return;
v8::HandleScope scope(m_isolate);
std::shared_ptr<AsyncStackTrace> asyncStack = AsyncStackTrace::capture(
this, taskName, V8StackTraceImpl::maxCallStackSizeToCapture,
this, toString16(taskName), V8StackTraceImpl::maxCallStackSizeToCapture,
skipTopFrame);
if (asyncStack) {
m_asyncTaskStacks[task] = asyncStack;
......
......@@ -161,7 +161,7 @@ class V8Debugger : public v8::debug::DebugDelegate,
v8::MaybeLocal<v8::Array> collectionsEntries(v8::Local<v8::Context> context,
v8::Local<v8::Value> value);
void asyncTaskScheduledForStack(const String16& taskName, void* task,
void asyncTaskScheduledForStack(const StringView& taskName, void* task,
bool recurring, bool skipTopFrame = false);
void asyncTaskCanceledForStack(void* task);
void asyncTaskStartedForStack(void* task);
......
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