MCPcopy Create free account
hub / github.com/apache/impala / FastUInt32ToBufferLeft

Function FastUInt32ToBufferLeft

be/src/gutil/strings/numbers.cc:932–1012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

930// ----------------------------------------------------------------------
931
932char* FastUInt32ToBufferLeft(uint32 u, char* buffer) {
933 uint digits;
934 const char *ASCII_digits = nullptr;
935 // The idea of this implementation is to trim the number of divides to as few
936 // as possible by using multiplication and subtraction rather than mod (%),
937 // and by outputting two digits at a time rather than one.
938 // The huge-number case is first, in the hopes that the compiler will output
939 // that case in one branch-free block of code, and only output conditional
940 // branches into it from below.
941 if (u >= 1000000000) { // >= 1,000,000,000
942 digits = u / 100000000; // 100,000,000
943 ASCII_digits = two_ASCII_digits[digits];
944 buffer[0] = ASCII_digits[0];
945 buffer[1] = ASCII_digits[1];
946 buffer += 2;
947 sublt100_000_000:
948 u -= digits * 100000000; // 100,000,000
949 lt100_000_000:
950 digits = u / 1000000; // 1,000,000
951 ASCII_digits = two_ASCII_digits[digits];
952 buffer[0] = ASCII_digits[0];
953 buffer[1] = ASCII_digits[1];
954 buffer += 2;
955 sublt1_000_000:
956 u -= digits * 1000000; // 1,000,000
957 lt1_000_000:
958 digits = u / 10000; // 10,000
959 ASCII_digits = two_ASCII_digits[digits];
960 buffer[0] = ASCII_digits[0];
961 buffer[1] = ASCII_digits[1];
962 buffer += 2;
963 sublt10_000:
964 u -= digits * 10000; // 10,000
965 lt10_000:
966 digits = u / 100;
967 ASCII_digits = two_ASCII_digits[digits];
968 buffer[0] = ASCII_digits[0];
969 buffer[1] = ASCII_digits[1];
970 buffer += 2;
971 sublt100:
972 u -= digits * 100;
973 lt100:
974 digits = u;
975 ASCII_digits = two_ASCII_digits[digits];
976 buffer[0] = ASCII_digits[0];
977 buffer[1] = ASCII_digits[1];
978 buffer += 2;
979 done:
980 *buffer = 0;
981 return buffer;
982 }
983
984 if (u < 100) {
985 digits = u;
986 if (u >= 10) goto lt100;
987 *buffer++ = '0' + digits;
988 goto done;
989 }

Callers 7

AlphaNumMethod · 0.85
SubstituteArgMethod · 0.85
FastInt32ToBufferLeftFunction · 0.85
FastUInt64ToBufferLeftFunction · 0.85
FastUInt128ToBufferLeftFunction · 0.85
FastUInt32ToBufferFunction · 0.85
SimpleItoaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected