Skip to content

Commit 9d22cc4

Browse files
committed
Fix formatting and undef cast_to_pair_ptr
1 parent 0e60e05 commit 9d22cc4

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

ext/json/ext/vendor/jeaiii-ltoa.h

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ struct pair
5151

5252
#define cast_to_pair_ptr(b) ((struct pair*)(void*)(b))
5353

54-
static struct pair digits_dd[100] =
55-
{
54+
static struct pair digits_dd[100] = {
5655
{ '0', '0' }, { '0', '1' }, { '0', '2' }, { '0', '3' }, { '0', '4' }, { '0', '5' }, { '0', '6' }, { '0', '7' }, { '0', '8' }, { '0', '9' },
5756
{ '1', '0' }, { '1', '1' }, { '1', '2' }, { '1', '3' }, { '1', '4' }, { '1', '5' }, { '1', '6' }, { '1', '7' }, { '1', '8' }, { '1', '9' },
5857
{ '2', '0' }, { '2', '1' }, { '2', '2' }, { '2', '3' }, { '2', '4' }, { '2', '5' }, { '2', '6' }, { '2', '7' }, { '2', '8' }, { '2', '9' },
@@ -67,8 +66,7 @@ static struct pair digits_dd[100] =
6766

6867
#define NUL 'x'
6968

70-
static struct pair digits_fd[100] =
71-
{
69+
static struct pair digits_fd[100] = {
7270
{ '0', NUL }, { '1', NUL }, { '2', NUL }, { '3', NUL }, { '4', NUL }, { '5', NUL }, { '6', NUL }, { '7', NUL }, { '8', NUL }, { '9', NUL },
7371
{ '1', '0' }, { '1', '1' }, { '1', '2' }, { '1', '3' }, { '1', '4' }, { '1', '5' }, { '1', '6' }, { '1', '7' }, { '1', '8' }, { '1', '9' },
7472
{ '2', '0' }, { '2', '1' }, { '2', '2' }, { '2', '3' }, { '2', '4' }, { '2', '5' }, { '2', '6' }, { '2', '7' }, { '2', '8' }, { '2', '9' },
@@ -87,17 +85,16 @@ static u64_t mask24 = (u64(1) << 24) - 1;
8785
static u64_t mask32 = (u64(1) << 32) - 1;
8886
static u64_t mask57 = (u64(1) << 57) - 1;
8987

90-
static
91-
char* to_text_from_ulong(char* b, u64_t n) {
92-
if (n < u32(1e2))
93-
{
88+
static
89+
char* to_text_from_ulong(char* b, u64_t n)
90+
{
91+
if (n < u32(1e2)) {
9492
*cast_to_pair_ptr(b) = digits_fd[n];
9593
return n < 10 ? b + 1 : b + 2;
9694
}
97-
if (n < u32(1e6))
98-
{
99-
if (n < u32(1e4))
100-
{
95+
96+
if (n < u32(1e6)) {
97+
if (n < u32(1e4)) {
10198
u32_t f0 = u32(10 * (1 << 24) / 1e3 + 1) * n;
10299
*cast_to_pair_ptr(b) = digits_fd[f0 >> 24];
103100
b -= n < u32(1e3);
@@ -114,10 +111,9 @@ char* to_text_from_ulong(char* b, u64_t n) {
114111
*cast_to_pair_ptr(b + 4) = digits_dd[f4 >> 32];
115112
return b + 6;
116113
}
117-
if (n < u64(1ull << 32ull))
118-
{
119-
if (n < u32(1e8))
120-
{
114+
115+
if (n < u64(1ull << 32ull)) {
116+
if (n < u32(1e8)) {
121117
u64_t f0 = u64(10 * (1ull << 48ull) / 1e7 + 1) * n >> 16;
122118
*cast_to_pair_ptr(b) = digits_fd[f0 >> 32];
123119
b -= n < u32(1e7);
@@ -147,25 +143,21 @@ char* to_text_from_ulong(char* b, u64_t n) {
147143
u32_t z = n % u32(1e8);
148144
u64_t u = n / u32(1e8);
149145

150-
if (u < u32(1e2))
151-
{
146+
if (u < u32(1e2)) {
152147
// u can't be 1 digit (if u < 10 it would have been handled above as a 9 digit 32bit number)
153148
*cast_to_pair_ptr(b) = digits_dd[u];
154149
b += 2;
155150
}
156-
else if (u < u32(1e6))
157-
{
158-
if (u < u32(1e4))
159-
{
151+
else if (u < u32(1e6)) {
152+
if (u < u32(1e4)) {
160153
u32_t f0 = u32(10 * (1 << 24) / 1e3 + 1) * u;
161154
*cast_to_pair_ptr(b) = digits_fd[f0 >> 24];
162155
b -= u < u32(1e3);
163156
u32_t f2 = (f0 & mask24) * 100;
164157
*cast_to_pair_ptr(b + 2) = digits_dd[f2 >> 24];
165158
b += 4;
166159
}
167-
else
168-
{
160+
else {
169161
u64_t f0 = u64(10 * (1ull << 32ull) / 1e5 + 1) * u;
170162
*cast_to_pair_ptr(b) = digits_fd[f0 >> 32];
171163
b -= u < u32(1e5);
@@ -176,8 +168,7 @@ char* to_text_from_ulong(char* b, u64_t n) {
176168
b += 6;
177169
}
178170
}
179-
else if (u < u32(1e8))
180-
{
171+
else if (u < u32(1e8)) {
181172
u64_t f0 = u64(10 * (1ull << 48ull) / 1e7 + 1) * u >> 16;
182173
*cast_to_pair_ptr(b) = digits_fd[f0 >> 32];
183174
b -= u < u32(1e7);
@@ -189,8 +180,7 @@ char* to_text_from_ulong(char* b, u64_t n) {
189180
*cast_to_pair_ptr(b + 6) = digits_dd[f6 >> 32];
190181
b += 8;
191182
}
192-
else if (u < u64(1ull << 32ull))
193-
{
183+
else if (u < u64(1ull << 32ull)) {
194184
u64_t f0 = u64(10 * (1ull << 57ull) / 1e9 + 1) * u;
195185
*cast_to_pair_ptr(b) = digits_fd[f0 >> 57];
196186
b -= u < u32(1e9);
@@ -204,19 +194,16 @@ char* to_text_from_ulong(char* b, u64_t n) {
204194
*cast_to_pair_ptr(b + 8) = digits_dd[f8 >> 57];
205195
b += 10;
206196
}
207-
else
208-
{
197+
else {
209198
u32_t y = u % u32(1e8);
210199
u /= u32(1e8);
211200

212201
// u is 2, 3, or 4 digits (if u < 10 it would have been handled above)
213-
if (u < u32(1e2))
214-
{
202+
if (u < u32(1e2)) {
215203
*cast_to_pair_ptr(b) = digits_dd[u];
216204
b += 2;
217205
}
218-
else
219-
{
206+
else {
220207
u32_t f0 = u32(10 * (1 << 24) / 1e3 + 1) * u;
221208
*cast_to_pair_ptr(b) = digits_fd[f0 >> 24];
222209
b -= u < u32(1e3);
@@ -249,6 +236,7 @@ char* to_text_from_ulong(char* b, u64_t n) {
249236

250237
#undef u32
251238
#undef u64
239+
#undef cast_to_pair_ptr
252240

253241
#pragma clang diagnostic pop
254242
#pragma GCC diagnostic pop

0 commit comments

Comments
 (0)