Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfd2e2d0

Browse files
committed
Rewrite pg_size_pretty() to avoid compiler bug.
Convert it to use successive shifts right instead of increasing a divisor.This is probably a tad more efficient than the original coding, and it'snicer-looking than the previous patch because we don't need a special caseto avoid overflow in the last branch. But the real reason to do it is toavoid a Solaris compiler bug, as per results from buildfarm member moa.
1 parentc49e4ae commitfd2e2d0

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

‎src/backend/utils/adt/dbsize.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -466,39 +466,33 @@ pg_size_pretty(PG_FUNCTION_ARGS)
466466
int64size=PG_GETARG_INT64(0);
467467
charbuf[64];
468468
int64limit=10*1024;
469-
int64mult=1;
469+
int64limit2=limit*2-1;
470470

471-
if (size<limit*mult)
471+
if (size<limit)
472472
snprintf(buf,sizeof(buf),INT64_FORMAT" bytes",size);
473473
else
474474
{
475-
mult *=1024;
476-
if (size<limit*mult)
475+
size >>=9;/* keep one extra bit for rounding */
476+
if (size<limit2)
477477
snprintf(buf,sizeof(buf),INT64_FORMAT" kB",
478-
(size+mult /2) /mult);
478+
(size+1) /2);
479479
else
480480
{
481-
mult *=1024;
482-
if (size<limit*mult)
481+
size >>=10;
482+
if (size<limit2)
483483
snprintf(buf,sizeof(buf),INT64_FORMAT" MB",
484-
(size+mult /2) /mult);
484+
(size+1) /2);
485485
else
486486
{
487-
mult *=1024;
488-
if (size<limit*mult)
487+
size >>=10;
488+
if (size<limit2)
489489
snprintf(buf,sizeof(buf),INT64_FORMAT" GB",
490-
(size+mult /2) /mult);
490+
(size+1) /2);
491491
else
492492
{
493-
/* Here we have to worry about avoiding overflow */
494-
int64val;
495-
496-
mult *=1024;
497-
val=size /mult;
498-
if ((size %mult) >= (mult /2))
499-
val++;
493+
size >>=10;
500494
snprintf(buf,sizeof(buf),INT64_FORMAT" TB",
501-
val);
495+
(size+1) /2);
502496
}
503497
}
504498
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp