eldenmoon commented on code in PR #22917:
URL: https://github.com/apache/doris/pull/22917#discussion_r1292939904


##########
be/src/util/jsonb_stream.h:
##########
@@ -126,9 +130,40 @@ class JsonbOutStream : public std::ostream {
         size_ += len;
     }
 
-    void write(__int128 l) {
-        // TODO
-        assert(false);
+    // TODO: use more efficient impl for int128
+    void write(int128_t l) {
+        // snprintf automatically adds a NULL, so we need one more char
+        if (size_ + MAX_INT128_DIGITS + 1 > capacity_) {
+            realloc(MAX_INT128_DIGITS + 1);
+        }
+
+        int len = 0;
+        // output negtive sign
+        if (l < 0) {
+            *(head_ + size_) = '-';
+            size_ += 1;
+        }
+
+        uint32_t start_size = size_;
+
+        // snprintf from low digit to high digit
+        while (l != 0) {
+            // get lowest digit
+            int n = l % 10;
+            if (n < 0) {
+                n = 0 - n;
+            }
+            assert(n >= 0 && n < 10);
+            len = snprintf(head_ + size_, MAX_INT128_DIGITS, "%d", n);

Review Comment:
   this is slow



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to