taepper commented on code in PR #50945:
URL: https://github.com/apache/arrow/pull/50945#discussion_r3981716140


##########
cpp/src/arrow/json/chunker.cc:
##########
@@ -165,6 +91,78 @@ class ParsingBoundaryFinder : public BoundaryFinder {
                  int64_t* out_pos, int64_t* num_found) override {
     return Status::NotImplemented("ParsingBoundaryFinder::FindNth");
   }
+
+ private:
+  simdjson::ondemand::parser parser_;
+  // A persistent buffer to keep padded contents for simdjson.
+  // This should be more efficient than allocating a new padded_string 
everytime.
+  std::string buffer_;
+
+  simdjson::padded_string_view GetPaddedStringView(std::string_view partial,
+                                                   std::string_view block = 
{}) {
+    // Adjust buffer size without copying old contents.
+    buffer_.clear();
+    buffer_.reserve(partial.size() + block.size() + 
simdjson::SIMDJSON_PADDING);
+    buffer_.append(partial);
+    buffer_.append(block);
+    // XXX Hopefully this upholds for all std::string implementations
+    DCHECK_GE(buffer_.capacity() - buffer_.size(), simdjson::SIMDJSON_PADDING);

Review Comment:
   We could avoid the comment and assertion if we instead resize the buffer to 
include padding and then construct an intermediate 
std::string_view{buffer_.data(), partial.size() + block.size()}



##########
cpp/src/arrow/json/chunker.cc:
##########
@@ -165,6 +91,78 @@ class ParsingBoundaryFinder : public BoundaryFinder {
                  int64_t* out_pos, int64_t* num_found) override {
     return Status::NotImplemented("ParsingBoundaryFinder::FindNth");
   }
+
+ private:
+  simdjson::ondemand::parser parser_;
+  // A persistent buffer to keep padded contents for simdjson.
+  // This should be more efficient than allocating a new padded_string 
everytime.
+  std::string buffer_;
+
+  simdjson::padded_string_view GetPaddedStringView(std::string_view partial,
+                                                   std::string_view block = 
{}) {
+    // Adjust buffer size without copying old contents.
+    buffer_.clear();
+    buffer_.reserve(partial.size() + block.size() + 
simdjson::SIMDJSON_PADDING);
+    buffer_.append(partial);
+    buffer_.append(block);
+    // XXX Hopefully this upholds for all std::string implementations
+    DCHECK_GE(buffer_.capacity() - buffer_.size(), simdjson::SIMDJSON_PADDING);

Review Comment:
   We could avoid the comment and assertion if we instead resize the buffer to 
include padding and then construct an intermediate 
`std::string_view{buffer_.data(), partial.size() + block.size()}`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to