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

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


The following commit(s) were added to refs/heads/master by this push:
     new 81ea6d79331 [opt](string_to_unsigned_int) performance opt (#30825)
81ea6d79331 is described below

commit 81ea6d793313b565233a395329c96869c8da1c65
Author: zhiqiang <seuhezhiqi...@163.com>
AuthorDate: Mon Feb 5 22:06:56 2024 +0800

    [opt](string_to_unsigned_int) performance opt (#30825)
---
 be/src/util/string_parser.hpp | 55 +++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 23 deletions(-)

diff --git a/be/src/util/string_parser.hpp b/be/src/util/string_parser.hpp
index 3a72250d2fa..521d1a6f39c 100644
--- a/be/src/util/string_parser.hpp
+++ b/be/src/util/string_parser.hpp
@@ -102,7 +102,7 @@ public:
     // In the case of overflow, the max/min value for the data type will be 
returned.
     // Assumes s represents a decimal number.
     template <typename T>
-    static inline T string_to_int(const char* s, int len, ParseResult* result) 
{
+    static inline T string_to_int(const char* __restrict s, int len, 
ParseResult* result) {
         T ans = string_to_int_internal<T>(s, len, result);
         if (LIKELY(*result == PARSE_SUCCESS)) {
             return ans;
@@ -116,7 +116,7 @@ public:
     // In the case of overflow, the max/min value for the data type will be 
returned.
     // Assumes s represents a decimal number.
     template <typename T>
-    static inline T string_to_unsigned_int(const char* s, int len, 
ParseResult* result) {
+    static inline T string_to_unsigned_int(const char* __restrict s, int len, 
ParseResult* result) {
         T ans = string_to_unsigned_int_internal<T>(s, len, result);
         if (LIKELY(*result == PARSE_SUCCESS)) {
             return ans;
@@ -128,7 +128,8 @@ public:
 
     // Convert a string s representing a number in given base into a decimal 
number.
     template <typename T>
-    static inline T string_to_int(const char* s, int len, int base, 
ParseResult* result) {
+    static inline T string_to_int(const char* __restrict s, int len, int base,
+                                  ParseResult* result) {
         T ans = string_to_int_internal<T>(s, len, base, result);
         if (LIKELY(*result == PARSE_SUCCESS)) {
             return ans;
@@ -139,12 +140,12 @@ public:
     }
 
     template <typename T>
-    static inline T string_to_float(const char* s, int len, ParseResult* 
result) {
+    static inline T string_to_float(const char* __restrict s, int len, 
ParseResult* result) {
         return string_to_float_internal<T>(s, len, result);
     }
 
     // Parses a string for 'true' or 'false', case insensitive.
-    static inline bool string_to_bool(const char* s, int len, ParseResult* 
result) {
+    static inline bool string_to_bool(const char* __restrict s, int len, 
ParseResult* result) {
         bool ans = string_to_bool_internal(s, len, result);
         if (LIKELY(*result == PARSE_SUCCESS)) {
             return ans;
@@ -156,8 +157,8 @@ public:
 
     template <PrimitiveType P, typename T = 
PrimitiveTypeTraits<P>::CppType::NativeType,
               typename DecimalType = 
PrimitiveTypeTraits<P>::ColumnType::value_type>
-    static inline T string_to_decimal(const char* s, int len, int 
type_precision, int type_scale,
-                                      ParseResult* result);
+    static inline T string_to_decimal(const char* __restrict s, int len, int 
type_precision,
+                                      int type_scale, ParseResult* result);
 
     template <typename T>
     static Status split_string_to_map(const std::string& base, const T 
element_separator,
@@ -193,25 +194,28 @@ private:
     // Assumes s represents a decimal number.
     // Return PARSE_FAILURE on leading whitespace. Trailing whitespace is 
allowed.
     template <typename T>
-    static inline T string_to_int_internal(const char* s, int len, 
ParseResult* result);
+    static inline T string_to_int_internal(const char* __restrict s, int len, 
ParseResult* result);
 
     // This is considerably faster than glibc's implementation.
     // In the case of overflow, the max/min value for the data type will be 
returned.
     // Assumes s represents a decimal number.
     // Return PARSE_FAILURE on leading whitespace. Trailing whitespace is 
allowed.
     template <typename T>
-    static inline T string_to_unsigned_int_internal(const char* s, int len, 
ParseResult* result);
+    static inline T string_to_unsigned_int_internal(const char* __restrict s, 
int len,
+                                                    ParseResult* result);
 
     // Convert a string s representing a number in given base into a decimal 
number.
     // Return PARSE_FAILURE on leading whitespace. Trailing whitespace is 
allowed.
     template <typename T>
-    static inline T string_to_int_internal(const char* s, int len, int base, 
ParseResult* result);
+    static inline T string_to_int_internal(const char* __restrict s, int len, 
int base,
+                                           ParseResult* result);
 
     // Converts an ascii string to an integer of type T assuming it cannot 
overflow
     // and the number is positive.
     // Leading whitespace is not allowed. Trailing whitespace will be skipped.
     template <typename T>
-    static inline T string_to_int_no_overflow(const char* s, int len, 
ParseResult* result);
+    static inline T string_to_int_no_overflow(const char* __restrict s, int 
len,
+                                              ParseResult* result);
 
     // This is considerably faster than glibc's implementation (>100x why???)
     // No special case handling needs to be done for overflows, the floating 
point spec
@@ -221,14 +225,16 @@ private:
     // Return PARSE_FAILURE on leading whitespace. Trailing whitespace is 
allowed.
     // TODO: Investigate using intrinsics to speed up the slow strtod path.
     template <typename T>
-    static inline T string_to_float_internal(const char* s, int len, 
ParseResult* result);
+    static inline T string_to_float_internal(const char* __restrict s, int len,
+                                             ParseResult* result);
 
     // parses a string for 'true' or 'false', case insensitive
     // Return PARSE_FAILURE on leading whitespace. Trailing whitespace is 
allowed.
-    static inline bool string_to_bool_internal(const char* s, int len, 
ParseResult* result);
+    static inline bool string_to_bool_internal(const char* __restrict s, int 
len,
+                                               ParseResult* result);
 
     // Returns true if s only contains whitespace.
-    static inline bool is_all_whitespace(const char* s, int len) {
+    static inline bool is_all_whitespace(const char* __restrict s, int len) {
         for (int i = 0; i < len; ++i) {
             if (!LIKELY(is_whitespace(s[i]))) {
                 return false;
@@ -238,7 +244,7 @@ private:
     }
 
     // Returns the position of the first non-whitespace character in s.
-    static inline int skip_leading_whitespace(const char* s, int len) {
+    static inline int skip_leading_whitespace(const char* __restrict s, int 
len) {
         int i = 0;
         while (i < len && is_whitespace(s[i])) {
             ++i;
@@ -255,7 +261,7 @@ private:
 }; // end of class StringParser
 
 template <typename T>
-T StringParser::string_to_int_internal(const char* s, int len, ParseResult* 
result) {
+T StringParser::string_to_int_internal(const char* __restrict s, int len, 
ParseResult* result) {
     if (UNLIKELY(len <= 0)) {
         *result = PARSE_FAILURE;
         return 0;
@@ -311,7 +317,8 @@ T StringParser::string_to_int_internal(const char* s, int 
len, ParseResult* resu
 }
 
 template <typename T>
-T StringParser::string_to_unsigned_int_internal(const char* s, int len, 
ParseResult* result) {
+T StringParser::string_to_unsigned_int_internal(const char* __restrict s, int 
len,
+                                                ParseResult* result) {
     if (UNLIKELY(len <= 0)) {
         *result = PARSE_FAILURE;
         return 0;
@@ -358,7 +365,8 @@ T StringParser::string_to_unsigned_int_internal(const char* 
s, int len, ParseRes
 }
 
 template <typename T>
-T StringParser::string_to_int_internal(const char* s, int len, int base, 
ParseResult* result) {
+T StringParser::string_to_int_internal(const char* __restrict s, int len, int 
base,
+                                       ParseResult* result) {
     typedef typename std::make_unsigned<T>::type UnsignedT;
     UnsignedT val = 0;
     UnsignedT max_val = StringParser::numeric_limits<T>(false);
@@ -417,7 +425,7 @@ T StringParser::string_to_int_internal(const char* s, int 
len, int base, ParseRe
 }
 
 template <typename T>
-T StringParser::string_to_int_no_overflow(const char* s, int len, ParseResult* 
result) {
+T StringParser::string_to_int_no_overflow(const char* __restrict s, int len, 
ParseResult* result) {
     T val = 0;
     if (UNLIKELY(len == 0)) {
         *result = PARSE_SUCCESS;
@@ -448,7 +456,7 @@ T StringParser::string_to_int_no_overflow(const char* s, 
int len, ParseResult* r
 }
 
 template <typename T>
-T StringParser::string_to_float_internal(const char* s, int len, ParseResult* 
result) {
+T StringParser::string_to_float_internal(const char* __restrict s, int len, 
ParseResult* result) {
     int i = 0;
     // skip leading spaces
     for (; i < len; ++i) {
@@ -499,7 +507,8 @@ T StringParser::string_to_float_internal(const char* s, int 
len, ParseResult* re
     return 0;
 }
 
-inline bool StringParser::string_to_bool_internal(const char* s, int len, 
ParseResult* result) {
+inline bool StringParser::string_to_bool_internal(const char* __restrict s, 
int len,
+                                                  ParseResult* result) {
     *result = PARSE_SUCCESS;
 
     if (len >= 4 && (s[0] == 't' || s[0] == 'T')) {
@@ -521,8 +530,8 @@ inline bool StringParser::string_to_bool_internal(const 
char* s, int len, ParseR
 }
 
 template <PrimitiveType P, typename T, typename DecimalType>
-T StringParser::string_to_decimal(const char* s, int len, int type_precision, 
int type_scale,
-                                  ParseResult* result) {
+T StringParser::string_to_decimal(const char* __restrict s, int len, int 
type_precision,
+                                  int type_scale, ParseResult* result) {
     static_assert(std::is_same_v<T, int32_t> || std::is_same_v<T, int64_t> ||
                           std::is_same_v<T, __int128> || std::is_same_v<T, 
wide::Int256>,
                   "Cast string to decimal only support target type int32_t, 
int64_t, __int128 or "


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

Reply via email to