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
This commit is contained in:
Simon Giesecke 2020-12-16 19:10:06 +00:00
Родитель 29c054ab83
Коммит fe1c53bd2d
4 изменённых файлов: 25 добавлений и 31 удалений

Просмотреть файл

@ -26,9 +26,8 @@ namespace mozilla::dom::indexedDB {
namespace {
inline bool IgnoreWhitespace(char16_t c) { return false; }
typedef nsCharSeparatedTokenizerTemplate<IgnoreWhitespace> KeyPathTokenizer;
using KeyPathTokenizer =
nsCharSeparatedTokenizerTemplate<NS_TokenizerIgnoreNothing>;
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<IgnoreWhitespace> tokenizer(aString, ',');
nsCharSeparatedTokenizerTemplate<NS_TokenizerIgnoreNothing> tokenizer(
aString, ',');
tokenizer.nextToken();
while (tokenizer.hasMoreTokens()) {
keyPath.mStrings.AppendElement(tokenizer.nextToken());

Просмотреть файл

@ -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<IgnoreWhitespace> Tokenizer;
using Tokenizer =
nsCCharSeparatedTokenizerTemplate<NS_TokenizerIgnoreNothing>;
enum SchemeType { eNone, eFile, eAbout, eChrome };

Просмотреть файл

@ -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<IgnoreWhitespace> Tokenizer;
typedef nsCharSeparatedTokenizerTemplate<NS_TokenizerIgnoreNothing>
Tokenizer;
Tokenizer tokenizer(tokenList, ' ');
nsAutoString token;

Просмотреть файл

@ -146,35 +146,31 @@ class nsTCharSeparatedTokenizer {
private:
mozilla::RangedPtr<const CharType> mIter;
const mozilla::RangedPtr<const CharType> mEnd;
CharType mSeparatorChar;
const CharType mSeparatorChar;
bool mWhitespaceBeforeFirstToken;
bool mWhitespaceAfterCurrentToken;
bool mSeparatorAfterCurrentToken;
bool mSeparatorOptional;
};
template <bool IsWhitespace(char16_t) = NS_IsAsciiWhitespace>
class nsCharSeparatedTokenizerTemplate
: public nsTCharSeparatedTokenizer<nsDependentSubstring, IsWhitespace> {
public:
nsCharSeparatedTokenizerTemplate(const nsAString& aSource,
char16_t aSeparatorChar, uint32_t aFlags = 0)
: nsTCharSeparatedTokenizer<nsDependentSubstring, IsWhitespace>(
aSource, aSeparatorChar, aFlags) {}
};
constexpr bool NS_TokenizerIgnoreNothing(char16_t) { return false; }
typedef nsCharSeparatedTokenizerTemplate<> nsCharSeparatedTokenizer;
template <bool IsWhitespace(char16_t), typename CharType>
using nsTCharSeparatedTokenizerTemplate =
nsTCharSeparatedTokenizer<nsTDependentSubstring<CharType>, IsWhitespace>;
template <bool IsWhitespace(char16_t) = NS_IsAsciiWhitespace>
class nsCCharSeparatedTokenizerTemplate
: public nsTCharSeparatedTokenizer<nsDependentCSubstring, IsWhitespace> {
public:
nsCCharSeparatedTokenizerTemplate(const nsACString& aSource,
char aSeparatorChar, uint32_t aFlags = 0)
: nsTCharSeparatedTokenizer<nsDependentCSubstring, IsWhitespace>(
aSource, aSeparatorChar, aFlags) {}
};
template <bool IsWhitespace(char16_t)>
using nsCharSeparatedTokenizerTemplate =
nsTCharSeparatedTokenizerTemplate<IsWhitespace, char16_t>;
typedef nsCCharSeparatedTokenizerTemplate<> nsCCharSeparatedTokenizer;
using nsCharSeparatedTokenizer =
nsCharSeparatedTokenizerTemplate<NS_IsAsciiWhitespace>;
template <bool IsWhitespace(char16_t)>
using nsCCharSeparatedTokenizerTemplate =
nsTCharSeparatedTokenizerTemplate<IsWhitespace, char>;
using nsCCharSeparatedTokenizer =
nsCCharSeparatedTokenizerTemplate<NS_IsAsciiWhitespace>;
#endif /* __nsCharSeparatedTokenizer_h */