Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1440)

Unified Diff: extensions/renderer/user_script_injector.cc

Issue 2250263004: [Extensions] Reduce string copy in renderer/ UserScript. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/user_script_injector.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/user_script_injector.cc
diff --git a/extensions/renderer/user_script_injector.cc b/extensions/renderer/user_script_injector.cc
index 21a59eac30fa4bd3e03c928090db5f13e6189ed9..c9bd11e9935612bda3037b859bbe788c9c7e94b6 100644
--- a/extensions/renderer/user_script_injector.cc
+++ b/extensions/renderer/user_script_injector.cc
@@ -207,16 +207,25 @@ std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
for (UserScript::FileList::const_iterator iter = js_scripts.begin();
iter != js_scripts.end();
++iter) {
- std::string content = iter->GetContent().as_string();
-
- // We add this dumb function wrapper for user scripts to emulate what
- // Greasemonkey does.
+ base::StringPiece script_content = iter->GetContent();
if (script_->emulate_greasemonkey()) {
- content.insert(0, kUserScriptHead);
- content += kUserScriptTail;
+ // We add this dumb function wrapper for user scripts to emulate what
+ // Greasemonkey does: |script_content| becomes:
Devlin 2016/08/18 17:08:16 nit: replace the first ':' (after 'does') with a '
lazyboy 2016/08/18 18:53:23 Done.
+ // concat(kUserScriptHead, script_content, kUserScriptTail)
+ std::string content;
+ content.reserve(strlen(kUserScriptHead) + content.length() +
+ strlen(kUserScriptTail));
+ content.append(kUserScriptHead);
+ script_content.AppendToString(&content);
+ content.append(kUserScriptTail);
+ sources.push_back(blink::WebScriptSource(
+ blink::WebString::fromUTF8(content), iter->url()));
+ } else {
+ sources.push_back(blink::WebScriptSource(
Devlin 2016/08/18 17:08:16 We should keep some kind of TODO here to optimize
lazyboy 2016/08/18 18:53:23 Done.
+ blink::WebString::fromUTF8(script_content.data(),
Devlin 2016/08/18 17:08:16 hmm... I find it slightly more readable when we re
lazyboy 2016/08/18 18:53:23 Done.
+ script_content.length()),
+ iter->url()));
}
- sources.push_back(blink::WebScriptSource(
- blink::WebString::fromUTF8(content), iter->url()));
}
// Emulate Greasemonkey API for scripts that were converted to extension
@@ -227,19 +236,22 @@ std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
return sources;
}
-std::vector<std::string> UserScriptInjector::GetCssSources(
+std::vector<blink::WebString> UserScriptInjector::GetCssSources(
UserScript::RunLocation run_location) const {
DCHECK_EQ(UserScript::DOCUMENT_START, run_location);
- std::vector<std::string> sources;
+ std::vector<blink::WebString> sources;
if (!script_)
return sources;
const UserScript::FileList& css_scripts = script_->css_scripts();
+ sources.reserve(css_scripts.size());
for (UserScript::FileList::const_iterator iter = css_scripts.begin();
iter != css_scripts.end();
++iter) {
- sources.push_back(iter->GetContent().as_string());
+ base::StringPiece css_content = iter->GetContent();
+ sources.push_back(
+ blink::WebString::fromUTF8(css_content.data(), css_content.length()));
}
return sources;
}
« no previous file with comments | « extensions/renderer/user_script_injector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698