From 9ffa464dfb6a3f3fc7f8daed527e1a213ac74baa Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Fri, 29 Nov 2019 10:40:55 +0000 Subject: [PATCH] Bug 1596395 - Avoid copying of tokenizer token sub-strings. r=dom-workers-and-storage-reviewers,edenchuang Differential Revision: https://phabricator.services.mozilla.com/D53013 --HG-- extra : moz-landing-system : lando --- dom/indexedDB/ActorsParent.cpp | 5 ++--- dom/indexedDB/KeyPath.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index 48948b4812c8..c527d7fdc713 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -8564,7 +8564,7 @@ class MOZ_STACK_CLASS FileHelper final { bool TokenizerIgnoreNothing(char16_t /* aChar */) { return false; } nsresult DeserializeStructuredCloneFile(const FileManager& aFileManager, - const nsString& aText, + const nsDependentSubstring& aText, StructuredCloneFile* aFile) { MOZ_ASSERT(!aText.IsEmpty()); MOZ_ASSERT(aFile); @@ -8634,11 +8634,10 @@ nsresult DeserializeStructuredCloneFiles( nsCharSeparatedTokenizerTemplate tokenizer(aText, ' '); - nsAutoString token; nsresult rv; while (tokenizer.hasMoreTokens()) { - token = tokenizer.nextToken(); + const auto& token = tokenizer.nextToken(); MOZ_ASSERT(!token.IsEmpty()); auto* const file = aResult.EmplaceBack(StructuredCloneFile::eBlob); diff --git a/dom/indexedDB/KeyPath.cpp b/dom/indexedDB/KeyPath.cpp index 95fa325a0b25..37a943494476 100644 --- a/dom/indexedDB/KeyPath.cpp +++ b/dom/indexedDB/KeyPath.cpp @@ -36,13 +36,13 @@ bool IsValidKeyPathString(const nsAString& aKeyPath) { KeyPathTokenizer tokenizer(aKeyPath, '.'); while (tokenizer.hasMoreTokens()) { - nsString token(tokenizer.nextToken()); + const auto& token = tokenizer.nextToken(); if (!token.Length()) { return false; } - if (!JS_IsIdentifier(token.get(), token.Length())) { + if (!JS_IsIdentifier(token.Data(), token.Length())) { return false; } } @@ -76,7 +76,7 @@ nsresult GetJSValFromKeyPathString( JS::Rooted obj(aCx); while (tokenizer.hasMoreTokens()) { - const nsDependentSubstring& token = tokenizer.nextToken(); + const auto& token = tokenizer.nextToken(); NS_ASSERTION(!token.IsEmpty(), "Should be a valid keypath"); @@ -472,7 +472,7 @@ KeyPath KeyPath::DeserializeFromString(const nsAString& aString) { // There is a trailing comma, indicating the original KeyPath has // a trailing empty string, i.e. [..., '']. We should append this // empty string. - keyPath.mStrings.AppendElement(nsString{}); + keyPath.mStrings.EmplaceBack(); } return keyPath;