From fe1c53bd2d76ce6a8196ec33929ddcc3af0331b7 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 16 Dec 2020 19:10:06 +0000 Subject: [PATCH] Bug 1679987 - Convert tokenizer specializations from classes to type aliases. r=xpcom-reviewers,nika,necko-reviewers Currently, the tokenizer specializations are subclasses of the generic base template nsTCharSeparatedTokenizer. This is unnecessary with C++11 type aliases, as those subclasses only delegate to the base constructor. NS_TokenizerIgnoreNothing is introduced to replace several functions with the same effect across the codebase. Differential Revision: https://phabricator.services.mozilla.com/D98306 --- dom/indexedDB/KeyPath.cpp | 8 ++-- dom/quota/ActorsParent.cpp | 5 +-- .../antitracking/URLDecorationStripper.cpp | 5 +-- xpcom/ds/nsCharSeparatedTokenizer.h | 38 +++++++++---------- 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/dom/indexedDB/KeyPath.cpp b/dom/indexedDB/KeyPath.cpp index bb26d7eaf068..819bd8abed4c 100644 --- a/dom/indexedDB/KeyPath.cpp +++ b/dom/indexedDB/KeyPath.cpp @@ -26,9 +26,8 @@ namespace mozilla::dom::indexedDB { namespace { -inline bool IgnoreWhitespace(char16_t c) { return false; } - -typedef nsCharSeparatedTokenizerTemplate KeyPathTokenizer; +using KeyPathTokenizer = + nsCharSeparatedTokenizerTemplate; bool IsValidKeyPathString(const nsAString& aKeyPath) { NS_ASSERTION(!aKeyPath.IsVoid(), "What?"); @@ -463,7 +462,8 @@ KeyPath KeyPath::DeserializeFromString(const nsAString& aString) { // We use a comma in the beginning to indicate that it's an array of // key paths. This is to be able to tell a string-keypath from an // array-keypath which contains only one item. - nsCharSeparatedTokenizerTemplate tokenizer(aString, ','); + nsCharSeparatedTokenizerTemplate tokenizer( + aString, ','); tokenizer.nextToken(); while (tokenizer.hasMoreTokens()) { keyPath.mStrings.AppendElement(tokenizer.nextToken()); diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index b48b84b8ab34..94a49a27b57c 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -2213,9 +2213,8 @@ class MOZ_STACK_CLASS OriginParser final { enum ResultType { InvalidOrigin, ObsoleteOrigin, ValidOrigin }; private: - static bool IgnoreWhitespace(char16_t /* aChar */) { return false; } - - typedef nsCCharSeparatedTokenizerTemplate Tokenizer; + using Tokenizer = + nsCCharSeparatedTokenizerTemplate; enum SchemeType { eNone, eFile, eAbout, eChrome }; diff --git a/toolkit/components/antitracking/URLDecorationStripper.cpp b/toolkit/components/antitracking/URLDecorationStripper.cpp index 3c10458f7772..abf316c72226 100644 --- a/toolkit/components/antitracking/URLDecorationStripper.cpp +++ b/toolkit/components/antitracking/URLDecorationStripper.cpp @@ -16,8 +16,6 @@ namespace { static const char* kPrefName = "privacy.restrict3rdpartystorage.url_decorations"; - -inline bool IgnoreWhitespace(char16_t c) { return false; } } // namespace namespace mozilla { @@ -36,7 +34,8 @@ nsresult URLDecorationStripper::StripTrackingIdentifiers(nsIURI* aURI, int32_t queryBegins = path.FindChar('?'); // Only positive values are valid since the path must begin with a '/'. if (queryBegins > 0) { - typedef nsCharSeparatedTokenizerTemplate Tokenizer; + typedef nsCharSeparatedTokenizerTemplate + Tokenizer; Tokenizer tokenizer(tokenList, ' '); nsAutoString token; diff --git a/xpcom/ds/nsCharSeparatedTokenizer.h b/xpcom/ds/nsCharSeparatedTokenizer.h index 7685fb7681c4..1cdfae1f0fd7 100644 --- a/xpcom/ds/nsCharSeparatedTokenizer.h +++ b/xpcom/ds/nsCharSeparatedTokenizer.h @@ -146,35 +146,31 @@ class nsTCharSeparatedTokenizer { private: mozilla::RangedPtr mIter; const mozilla::RangedPtr mEnd; - CharType mSeparatorChar; + const CharType mSeparatorChar; bool mWhitespaceBeforeFirstToken; bool mWhitespaceAfterCurrentToken; bool mSeparatorAfterCurrentToken; bool mSeparatorOptional; }; -template -class nsCharSeparatedTokenizerTemplate - : public nsTCharSeparatedTokenizer { - public: - nsCharSeparatedTokenizerTemplate(const nsAString& aSource, - char16_t aSeparatorChar, uint32_t aFlags = 0) - : nsTCharSeparatedTokenizer( - aSource, aSeparatorChar, aFlags) {} -}; +constexpr bool NS_TokenizerIgnoreNothing(char16_t) { return false; } -typedef nsCharSeparatedTokenizerTemplate<> nsCharSeparatedTokenizer; +template +using nsTCharSeparatedTokenizerTemplate = + nsTCharSeparatedTokenizer, IsWhitespace>; -template -class nsCCharSeparatedTokenizerTemplate - : public nsTCharSeparatedTokenizer { - public: - nsCCharSeparatedTokenizerTemplate(const nsACString& aSource, - char aSeparatorChar, uint32_t aFlags = 0) - : nsTCharSeparatedTokenizer( - aSource, aSeparatorChar, aFlags) {} -}; +template +using nsCharSeparatedTokenizerTemplate = + nsTCharSeparatedTokenizerTemplate; -typedef nsCCharSeparatedTokenizerTemplate<> nsCCharSeparatedTokenizer; +using nsCharSeparatedTokenizer = + nsCharSeparatedTokenizerTemplate; + +template +using nsCCharSeparatedTokenizerTemplate = + nsTCharSeparatedTokenizerTemplate; + +using nsCCharSeparatedTokenizer = + nsCCharSeparatedTokenizerTemplate; #endif /* __nsCharSeparatedTokenizer_h */