commit 51da93ac268ff0b4814ea028a97a0b398582a95f
parent 1208012e44a40593781726e1026787463ac8d08e
Author: serge-sans-paille <sguelton@mozilla.com>
Date: Fri, 31 Oct 2025 08:03:36 +0000
Bug 1997204 - Remove unused mfbt inclusion in mfbt/** r=emilio
As a side effect, also move content of JSONWriter.cpp as a static
constexpr local variable in JSONWriter.h.
Differential Revision: https://phabricator.services.mozilla.com/D270617
Diffstat:
9 files changed, 39 insertions(+), 63 deletions(-)
diff --git a/memory/replace/dmd/moz.build b/memory/replace/dmd/moz.build
@@ -15,7 +15,6 @@ UNIFIED_SOURCES += [
if not CONFIG["MOZ_REPLACE_MALLOC_STATIC"]:
UNIFIED_SOURCES += [
"/mfbt/HashFunctions.cpp",
- "/mfbt/JSONWriter.cpp",
"/mfbt/Poison.cpp",
"/mozglue/misc/StackWalk.cpp",
]
diff --git a/memory/replace/logalloc/replay/moz.build b/memory/replace/logalloc/replay/moz.build
@@ -38,7 +38,6 @@ elif CONFIG["OS_TARGET"] == "Android":
if CONFIG["MOZ_REPLACE_MALLOC_STATIC"] and (CONFIG["MOZ_DMD"] or CONFIG["MOZ_PHC"]):
UNIFIED_SOURCES += [
"/mfbt/HashFunctions.cpp",
- "/mfbt/JSONWriter.cpp",
]
if CONFIG["OS_ARCH"] == "WINNT":
diff --git a/mfbt/JSONWriter.cpp b/mfbt/JSONWriter.cpp
@@ -1,47 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "mozilla/JSONWriter.h"
-
-namespace mozilla {
-namespace detail {
-
-// The chars with non-'___' entries in this table are those that can be
-// represented with a two-char escape sequence. The value is the second char in
-// the sequence, that which follows the initial backslash.
-#define ___ 0
-const char gTwoCharEscapes[256] = {
- /* 0 1 2 3 4 5 6 7 8 9 */
- /* 0+ */ ___, ___, ___, ___, ___, ___, ___, ___, 'b', 't',
- /* 10+ */ 'n', ___, 'f', 'r', ___, ___, ___, ___, ___, ___,
- /* 20+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 30+ */ ___, ___, ___, ___, '"', ___, ___, ___, ___, ___,
- /* 40+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 50+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 60+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 70+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 80+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 90+ */ ___, ___, '\\', ___, ___, ___, ___, ___, ___, ___,
- /* 100+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 110+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 120+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 130+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 140+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 150+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 160+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 170+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 180+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 190+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 200+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 210+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 220+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 230+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 240+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
- /* 250+ */ ___, ___, ___, ___, ___, ___};
-#undef ___
-
-} // namespace detail
-} // namespace mozilla
diff --git a/mfbt/JSONWriter.h b/mfbt/JSONWriter.h
@@ -113,12 +113,6 @@ class JSONWriteFunc {
virtual ~JSONWriteFunc() = default;
};
-// Ideally this would be within |EscapedString| but when compiling with GCC
-// on Linux that caused link errors, whereas this formulation didn't.
-namespace detail {
-extern MFBT_DATA const char gTwoCharEscapes[256];
-} // namespace detail
-
class JSONWriter {
// From http://www.ietf.org/rfc/rfc4627.txt:
//
@@ -153,6 +147,42 @@ class JSONWriter {
public:
explicit EscapedString(const Span<const char>& aStr) : mStringSpan(aStr) {
+ // clang-format off
+ // The chars with non-'___' entries in this table are those that can be
+ // represented with a two-char escape sequence. The value is the second char in
+ // the sequence, that which follows the initial backslash.
+ #define ___ 0
+ static constexpr char TwoCharEscapes[256] = {
+ /* 0 1 2 3 4 5 6 7 8 9 */
+ /* 0+ */ ___, ___, ___, ___, ___, ___, ___, ___, 'b', 't',
+ /* 10+ */ 'n', ___, 'f', 'r', ___, ___, ___, ___, ___, ___,
+ /* 20+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 30+ */ ___, ___, ___, ___, '"', ___, ___, ___, ___, ___,
+ /* 40+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 50+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 60+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 70+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 80+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 90+ */ ___, ___, '\\', ___, ___, ___, ___, ___, ___, ___,
+ /* 100+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 110+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 120+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 130+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 140+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 150+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 160+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 170+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 180+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 190+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 200+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 210+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 220+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 230+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 240+ */ ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
+ /* 250+ */ ___, ___, ___, ___, ___, ___};
+ #undef ___
+ // clang-format on
+
// First, see if we need to modify the string.
size_t nExtra = 0;
for (const char& c : aStr) {
@@ -167,7 +197,7 @@ class JSONWriter {
mStringSpan = mStringSpan.First(&c - mStringSpan.data());
break;
}
- if (detail::gTwoCharEscapes[u]) {
+ if (TwoCharEscapes[u]) {
nExtra += 1;
} else if (u <= 0x1f) {
nExtra += 5;
@@ -191,9 +221,9 @@ class JSONWriter {
// ensure it can't be interpreted as negative
uint8_t u = static_cast<uint8_t>(c);
MOZ_ASSERT(u != 0, "Null terminator should have been handled above");
- if (detail::gTwoCharEscapes[u]) {
+ if (TwoCharEscapes[u]) {
mOwnedStr[i++] = '\\';
- mOwnedStr[i++] = detail::gTwoCharEscapes[u];
+ mOwnedStr[i++] = TwoCharEscapes[u];
} else if (u <= 0x1f) {
mOwnedStr[i++] = '\\';
mOwnedStr[i++] = 'u';
diff --git a/mfbt/moz.build b/mfbt/moz.build
@@ -166,7 +166,6 @@ UNIFIED_SOURCES += [
"double-conversion/double-conversion/strtod.cc",
"FloatingPoint.cpp",
"HashFunctions.cpp",
- "JSONWriter.cpp",
"Poison.cpp",
"RandomNum.cpp",
"RefCounted.cpp",
diff --git a/mfbt/tests/TestBoundedMPSCQueue.cpp b/mfbt/tests/TestBoundedMPSCQueue.cpp
@@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/BoundedMPSCQueue.h"
-#include "mozilla/PodOperations.h"
#include <vector>
#include <iostream>
#include <thread>
diff --git a/mfbt/tests/TestCasting.cpp b/mfbt/tests/TestCasting.cpp
@@ -5,7 +5,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Casting.h"
-#include "mozilla/ThreadSafety.h"
#include <stdint.h>
#include <cstdint>
diff --git a/mfbt/tests/TestTextUtils.cpp b/mfbt/tests/TestTextUtils.cpp
@@ -4,7 +4,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "mozilla/Assertions.h"
#include "mozilla/TextUtils.h"
using mozilla::AsciiAlphanumericToNumber;
diff --git a/mfbt/tests/gtest/TestTainting.cpp b/mfbt/tests/gtest/TestTainting.cpp
@@ -9,7 +9,6 @@
#include "mozilla/Array.h"
#include "mozilla/Assertions.h"
-#include "mozilla/Range.h"
#include "mozilla/Tainting.h"
#include "nsTHashtable.h"
#include "nsHashKeys.h"