This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit d631fecea445dde0e91a49103e532deec704595d
Author: chao an <[email protected]>
AuthorDate: Mon Nov 2 11:31:16 2026 +0800

    libc/stdio: Batch fixed float zero runs
    
    Fixed-point formatting can generate long runs of zeroes for large
    precisions or values far from the decimal point.  Detect consecutive
    zero output and use the existing repeat helper so those runs are written
    in chunks instead of one byte at a time.
    
    Signed-off-by: chao an <[email protected]>
---
 libs/libc/stream/lib_libvsprintf.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/libs/libc/stream/lib_libvsprintf.c 
b/libs/libc/stream/lib_libvsprintf.c
index 83acd7da80e..fcc0d36f653 100644
--- a/libs/libc/stream/lib_libvsprintf.c
+++ b/libs/libc/stream/lib_libvsprintf.c
@@ -880,7 +880,32 @@ flt_oper:
                       break;
                     }
 
-                  stream_putc(out, stream);
+                  if (out == '0')
+                    {
+                      int zeroes = 1;
+
+                      while (n != -1)
+                        {
+                          int next = n - 1;
+                          int offset = exp - n;
+
+                          if (next < -prec ||
+                              (0 <= offset && offset < ndigs &&
+                               _dtoa.digits[offset] != '0'))
+                            {
+                              break;
+                            }
+
+                          zeroes++;
+                          n = next;
+                        }
+
+                      stream_repeat('0', zeroes, stream);
+                    }
+                  else
+                    {
+                      stream_putc(out, stream);
+                    }
                 }
               while (1);
 

Reply via email to