[llvm] 7082536 - [JSON] Prefer static to namespace {}. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 28 22:06:19 PDT 2024
Author: Fangrui Song
Date: 2024-06-28T22:06:14-07:00
New Revision: 70825368403202ab73900d8ff3dc096ddfef99b4
URL: https://github.com/llvm/llvm-project/commit/70825368403202ab73900d8ff3dc096ddfef99b4
DIFF: https://github.com/llvm/llvm-project/commit/70825368403202ab73900d8ff3dc096ddfef99b4.diff
LOG: [JSON] Prefer static to namespace {}. NFC
Added:
Modified:
llvm/lib/Support/JSON.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/JSON.cpp b/llvm/lib/Support/JSON.cpp
index 2f9c1df3d20b2..8f70d94827272 100644
--- a/llvm/lib/Support/JSON.cpp
+++ b/llvm/lib/Support/JSON.cpp
@@ -242,9 +242,7 @@ Error Path::Root::getError() const {
return createStringError(llvm::inconvertibleErrorCode(), OS.str());
}
-namespace {
-
-std::vector<const Object::value_type *> sortedElements(const Object &O) {
+static std::vector<const Object::value_type *> sortedElements(const Object &O) {
std::vector<const Object::value_type *> Elements;
for (const auto &E : O)
Elements.push_back(&E);
@@ -258,7 +256,7 @@ std::vector<const Object::value_type *> sortedElements(const Object &O) {
// Prints a one-line version of a value that isn't our main focus.
// We interleave writes to OS and JOS, exploiting the lack of extra buffering.
// This is OK as we own the implementation.
-void abbreviate(const Value &V, OStream &JOS) {
+static void abbreviate(const Value &V, OStream &JOS) {
switch (V.kind()) {
case Value::Array:
JOS.rawValue(V.getAsArray()->empty() ? "[]" : "[ ... ]");
@@ -284,7 +282,7 @@ void abbreviate(const Value &V, OStream &JOS) {
// Prints a semi-expanded version of a value that is our main focus.
// Array/Object entries are printed, but not recursively as they may be huge.
-void abbreviateChildren(const Value &V, OStream &JOS) {
+static void abbreviateChildren(const Value &V, OStream &JOS) {
switch (V.kind()) {
case Value::Array:
JOS.array([&] {
@@ -306,8 +304,6 @@ void abbreviateChildren(const Value &V, OStream &JOS) {
}
}
-} // namespace
-
void Path::Root::printErrorContext(const Value &R, raw_ostream &OS) const {
OStream JOS(OS, /*IndentSize=*/2);
// PrintValue recurses down the path, printing the ancestors of our target.
@@ -414,6 +410,7 @@ class Parser {
std::optional<Error> Err;
const char *Start, *P, *End;
};
+} // namespace
bool Parser::parseValue(Value &Out) {
eatWhitespace();
@@ -681,7 +678,6 @@ bool Parser::parseError(const char *Msg) {
std::make_unique<ParseError>(Msg, Line, P - StartOfLine, P - Start));
return false;
}
-} // namespace
Expected<Value> parse(StringRef JSON) {
Parser P(JSON);
More information about the llvm-commits
mailing list