Skip to content

Commit 620f256

Browse files
committed
64 bit integer to string conversion optimization
1 parent a90e86e commit 620f256

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

src/cloud_storage/DataOptions.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Created April 4, 2024
2+
* Created October 29, 2024
33
*
44
* The MIT License (MIT)
55
* Copyright (c) 2024 K. Suwatchai (Mobizt)
@@ -103,31 +103,31 @@ namespace GoogleCloudStorage
103103
public:
104104
BaseOptions &generation(uint64_t value)
105105
{
106-
buf[1] = "generation=" + sut.u64Str(value);
106+
buf[1] = "generation=" + sut.num2Str(value);
107107
return setBuf();
108108
}
109109

110110
BaseOptions &ifGenerationMatch(uint64_t value)
111111
{
112-
buf[2] = "ifGenerationMatch=" + sut.u64Str(value);
112+
buf[2] = "ifGenerationMatch=" + sut.num2Str(value);
113113
return setBuf();
114114
}
115115

116116
BaseOptions &ifGenerationNotMatch(uint64_t value)
117117
{
118-
buf[3] = "ifGenerationNotMatch=" + sut.u64Str(value);
118+
buf[3] = "ifGenerationNotMatch=" + sut.num2Str(value);
119119
return setBuf();
120120
}
121121

122122
BaseOptions &ifMetagenerationMatch(uint64_t value)
123123
{
124-
buf[4] = "ifMetagenerationMatch=" + sut.u64Str(value);
124+
buf[4] = "ifMetagenerationMatch=" + sut.num2Str(value);
125125
return setBuf();
126126
}
127127

128128
BaseOptions &ifMetagenerationNotMatch(uint64_t value)
129129
{
130-
buf[5] = "ifMetagenerationNotMatch=" + sut.u64Str(value);
130+
buf[5] = "ifMetagenerationNotMatch=" + sut.num2Str(value);
131131
return setBuf();
132132
}
133133
};
@@ -185,25 +185,25 @@ namespace GoogleCloudStorage
185185

186186
InsertOptions &ifGenerationMatch(uint64_t value)
187187
{
188-
buf[2] = "ifGenerationMatch=" + sut.u64Str(value);
188+
buf[2] = "ifGenerationMatch=" + sut.num2Str(value);
189189
return setBuf();
190190
}
191191

192192
InsertOptions &ifGenerationNotMatch(uint64_t value)
193193
{
194-
buf[3] = "ifGenerationNotMatch=" + sut.u64Str(value);
194+
buf[3] = "ifGenerationNotMatch=" + sut.num2Str(value);
195195
return setBuf();
196196
}
197197

198198
InsertOptions &ifMetagenerationMatch(uint64_t value)
199199
{
200-
buf[4] = "ifMetagenerationMatch=" + sut.u64Str(value);
200+
buf[4] = "ifMetagenerationMatch=" + sut.num2Str(value);
201201
return setBuf();
202202
}
203203

204204
InsertOptions &ifMetagenerationNotMatch(uint64_t value)
205205
{
206-
buf[5] = "ifMetagenerationNotMatch=" + sut.u64Str(value);
206+
buf[5] = "ifMetagenerationNotMatch=" + sut.num2Str(value);
207207
return setBuf();
208208
}
209209

src/core/StringUtil.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,6 @@ class StringUtil
9898

9999
void addSp(String &buf) { buf += ' '; }
100100

101-
String u64Str(uint64_t val)
102-
{
103-
// Some cores do not provide 64-bit integer to string conversion.
104-
String v;
105-
char buffer[21];
106-
char *ndx = &buffer[sizeof(buffer) - 1];
107-
*ndx = '\0';
108-
do
109-
{
110-
*--ndx = val % 10 + '0';
111-
val = val / 10;
112-
} while (val != 0);
113-
v = ndx;
114-
return v;
115-
}
116-
117101
// Some cores do not provide 64-bit integer to string conversion.
118102
template <typename T = uint64_t>
119103
auto num2Str(T val, bool negative = false) -> typename std::enable_if<(std::is_same<T, uint64_t>::value), String>::type

src/functions/DataOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Created June 12, 2024
2+
* Created October 29, 2024
33
*
44
* The MIT License (MIT)
55
* Copyright (c) 2024 K. Suwatchai (Mobizt)
@@ -466,7 +466,7 @@ namespace GoogleCloudFunctions
466466
// Maximum number of functions to return per call. The largest allowed pageSize is 1,000, if the pageSize is omitted or specified as greater than 1,000 then it will be replaced as 1,000. The size of the list response can be less than specified when used with filters.
467467
ListOptions &pageSize(uint64_t value)
468468
{
469-
buf[1] = "pageSize=" + sut.u64Str(value);
469+
buf[1] = "pageSize=" + sut.num2Str(value);
470470
return setBuf();
471471
}
472472

0 commit comments

Comments
 (0)