cyb70289 commented on a change in pull request #12504:
URL: https://github.com/apache/arrow/pull/12504#discussion_r813510537



##########
File path: cpp/src/arrow/csv/writer.cc
##########
@@ -265,24 +279,41 @@ class QuotedColumnPopulator : public ColumnPopulator {
 
   Status UpdateRowLengths(int32_t* row_lengths) override {
     const StringArray& input = *casted_array_;
-    int row_number = 0;
-    row_needs_escaping_.resize(casted_array_->length());
-    VisitArrayDataInline<StringType>(
-        *input.data(),
-        [&](arrow::util::string_view s) {
-          // Each quote in the value string needs to be escaped.
-          int64_t escaped_count = CountQuotes(s);
-          // TODO: Maybe use 64 bit row lengths or safe cast?
-          row_needs_escaping_[row_number] = escaped_count > 0;
-          row_lengths[row_number] += static_cast<int32_t>(s.length()) +
-                                     static_cast<int32_t>(escaped_count + 
kQuoteCount);
-          row_number++;
-        },
-        [&]() {
-          row_needs_escaping_[row_number] = false;
-          row_lengths[row_number] += 
static_cast<int32_t>(null_string_->size());
-          row_number++;
-        });
+
+    row_needs_escaping_.resize(casted_array_->length(), false);
+
+    if (NoQuoteInArray(input)) {

Review comment:
       Scan whole string array for quote in batch. Go fast path if there's no 
quote.
   It does introduces some overhead when there is quote in the array. Benchmark 
doesn't show regression as improvement in CountQuotes compensated it.




-- 
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