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

Commitcb0bcf4

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 parentc02bc63 commitcb0bcf4

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
@@ -473,39 +473,33 @@ pg_size_pretty(PG_FUNCTION_ARGS)
473473
int64size=PG_GETARG_INT64(0);
474474
charbuf[64];
475475
int64limit=10*1024;
476-
int64mult=1;
476+
int64limit2=limit*2-1;
477477

478-
if (size<limit*mult)
478+
if (size<limit)
479479
snprintf(buf,sizeof(buf),INT64_FORMAT" bytes",size);
480480
else
481481
{
482-
mult *=1024;
483-
if (size<limit*mult)
482+
size >>=9;/* keep one extra bit for rounding */
483+
if (size<limit2)
484484
snprintf(buf,sizeof(buf),INT64_FORMAT" kB",
485-
(size+mult /2) /mult);
485+
(size+1) /2);
486486
else
487487
{
488-
mult *=1024;
489-
if (size<limit*mult)
488+
size >>=10;
489+
if (size<limit2)
490490
snprintf(buf,sizeof(buf),INT64_FORMAT" MB",
491-
(size+mult /2) /mult);
491+
(size+1) /2);
492492
else
493493
{
494-
mult *=1024;
495-
if (size<limit*mult)
494+
size >>=10;
495+
if (size<limit2)
496496
snprintf(buf,sizeof(buf),INT64_FORMAT" GB",
497-
(size+mult /2) /mult);
497+
(size+1) /2);
498498
else
499499
{
500-
/* Here we have to worry about avoiding overflow */
501-
int64val;
502-
503-
mult *=1024;
504-
val=size /mult;
505-
if ((size %mult) >= (mult /2))
506-
val++;
500+
size >>=10;
507501
snprintf(buf,sizeof(buf),INT64_FORMAT" TB",
508-
val);
502+
(size+1) /2);
509503
}
510504
}
511505
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp