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

Method LargestSmallerString

be/src/runtime/string-value.cc:50–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50string StringValue::LargestSmallerString() const {
51 uint32_t len = Len();
52 if (len == 0) return "";
53 const char* ptr = Ptr();
54 if (len == 1 && ptr[0] == 0x00) return "";
55
56 int i = len - 1;
57 while (i >= 0 && ptr[i] == 0x00) i--;
58 if (UNLIKELY(i == -1)) {
59 // All characters are 0x00. Return a string with len-1 0x00 chars.
60 return string(len - 1, 0x00);
61 }
62
63 // i is pointing at a character != 0x00.
64 if (i < len - 1) {
65 // return 'this' without the last trailing 0x00
66 return string(ptr, len - 1);
67 }
68 DCHECK_EQ(i, len - 1);
69
70 // Copy characters of this in [0, i] to 'result' and perform a '-1' operation on the
71 // ith char.
72 string result;
73 result.reserve(i + 1);
74 // copy all i characters in [0, i-1] to 'result'
75 result.append(ptr, i);
76 // append a char which is ptr[i]-1
77 result.append(1, (uint8_t)(ptr[i]) - 1);
78 return result;
79}
80
81string StringValue::LeastLargerString() const {
82 uint32_t len = Len();

Callers 3

TEST_FFunction · 0.80
InsertForLTMethod · 0.80

Calls 2

reserveMethod · 0.80
appendMethod · 0.45

Tested by 2

TEST_FFunction · 0.64