Skip to content

Commit 67c36f2

Browse files
committed
work
1 parent f892fcf commit 67c36f2

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

cpp/src/arrow/integration/json_integration.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include "arrow/integration/json_integration.h"
1919

20+
#include <simdjson.h>
21+
2022
#include <cstddef>
2123
#include <cstdint>
2224
#include <memory>

cpp/src/arrow/integration/json_internal.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include "arrow/integration/json_internal.h"
1919

20+
#include <simdjson.h>
21+
2022
#include <cstdint>
2123
#include <cstdlib>
2224
#include <iomanip>

cpp/src/arrow/integration/json_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <string>
2323
#include <string_view>
2424

25+
#include <simdjson.h>
26+
2527
#include "arrow/ipc/type_fwd.h"
2628
#include "arrow/json/json_util.h"
2729
#include "arrow/result.h"

cpp/src/arrow/json/json_util.h

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717

1818
#pragma once
1919

20+
#include <charconv>
2021
#include <cstdint>
2122
#include <cstdio>
2223
#include <sstream>
2324
#include <string>
2425
#include <string_view>
2526

26-
#include <simdjson.h>
27-
2827
#include "arrow/util/visibility.h"
2928

3029
namespace arrow {
@@ -78,115 +77,111 @@ inline std::string EscapeJsonString(std::string_view s) {
7877
return ss.str();
7978
}
8079

81-
/// \brief JSON writer wrapper using simdjson
82-
///
83-
/// This class wraps simdjson's mini_formatter to provide a convenient API
84-
/// with automatic comma insertion between elements.
80+
/// \brief JSON writer with automatic comma insertion between elements.
8581
class JsonWriter {
8682
public:
8783
JsonWriter() = default;
8884

8985
void StartObject() {
9086
MaybeComma();
91-
formatter_.start_object();
87+
buffer_ += '{';
9288
needs_comma_ = false;
9389
}
9490

9591
void EndObject() {
96-
formatter_.end_object();
92+
buffer_ += '}';
9793
needs_comma_ = true;
9894
}
9995

10096
void StartArray() {
10197
MaybeComma();
102-
formatter_.start_array();
98+
buffer_ += '[';
10399
needs_comma_ = false;
104100
}
105101

106102
void EndArray() {
107-
formatter_.end_array();
103+
buffer_ += ']';
108104
needs_comma_ = true;
109105
}
110106

111107
void Key(std::string_view key) {
112108
MaybeComma();
113-
formatter_.key(key);
109+
buffer_ += EscapeJsonString(key);
110+
buffer_ += ':';
114111
needs_comma_ = false;
115112
}
116113

117114
void String(std::string_view value) {
118115
MaybeComma();
119-
formatter_.string(value);
116+
buffer_ += EscapeJsonString(value);
120117
needs_comma_ = true;
121118
}
122119

123120
void Bool(bool value) {
124121
MaybeComma();
125-
if (value) {
126-
formatter_.true_atom();
127-
} else {
128-
formatter_.false_atom();
129-
}
122+
buffer_ += value ? "true" : "false";
130123
needs_comma_ = true;
131124
}
132125

133126
void Int(int32_t value) {
134127
MaybeComma();
135-
formatter_.number(static_cast<int64_t>(value));
128+
buffer_ += std::to_string(value);
136129
needs_comma_ = true;
137130
}
138131

139132
void Int64(int64_t value) {
140133
MaybeComma();
141-
formatter_.number(value);
134+
buffer_ += std::to_string(value);
142135
needs_comma_ = true;
143136
}
144137

145138
void Uint(uint32_t value) {
146139
MaybeComma();
147-
formatter_.number(static_cast<uint64_t>(value));
140+
buffer_ += std::to_string(value);
148141
needs_comma_ = true;
149142
}
150143

151144
void Uint64(uint64_t value) {
152145
MaybeComma();
153-
formatter_.number(value);
146+
buffer_ += std::to_string(value);
154147
needs_comma_ = true;
155148
}
156149

157150
void Double(double value) {
158151
MaybeComma();
159-
formatter_.number(value);
152+
char buf[32];
153+
auto result = std::to_chars(buf, buf + sizeof(buf), value);
154+
buffer_.append(buf, result.ptr - buf);
160155
needs_comma_ = true;
161156
}
162157

163158
void Null() {
164159
MaybeComma();
165-
formatter_.null_atom();
160+
buffer_ += "null";
166161
needs_comma_ = true;
167162
}
168163

169164
/// Write a raw character (for unquoted values like decimal numbers)
170-
void RawChar(char c) { formatter_.one_char(c); }
165+
void RawChar(char c) { buffer_ += c; }
171166

172167
/// Mark that a raw value was written (for comma tracking)
173168
void MarkValueWritten() { needs_comma_ = true; }
174169

175-
std::string_view GetString() const { return formatter_.str(); }
170+
std::string_view GetString() const { return buffer_; }
176171

177172
void Clear() {
178-
formatter_.clear();
173+
buffer_.clear();
179174
needs_comma_ = false;
180175
}
181176

182177
private:
183178
void MaybeComma() {
184179
if (needs_comma_) {
185-
formatter_.comma();
180+
buffer_ += ',';
186181
}
187182
}
188183

189-
simdjson::internal::mini_formatter formatter_;
184+
std::string buffer_;
190185
bool needs_comma_ = false;
191186
};
192187

0 commit comments

Comments
 (0)