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

Commit9b51d50

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 parent1aa24e2 commit9b51d50

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
@@ -381,39 +381,33 @@ pg_size_pretty(PG_FUNCTION_ARGS)
381381
int64size=PG_GETARG_INT64(0);
382382
char*result=palloc(50+VARHDRSZ);
383383
int64limit=10*1024;
384-
int64mult=1;
384+
int64limit2=limit*2-1;
385385

386-
if (size<limit*mult)
386+
if (size<limit)
387387
snprintf(VARDATA(result),50,INT64_FORMAT" bytes",size);
388388
else
389389
{
390-
mult *=1024;
391-
if (size<limit*mult)
390+
size >>=9;/* keep one extra bit for rounding */
391+
if (size<limit2)
392392
snprintf(VARDATA(result),50,INT64_FORMAT" kB",
393-
(size+mult /2) /mult);
393+
(size+1) /2);
394394
else
395395
{
396-
mult *=1024;
397-
if (size<limit*mult)
396+
size >>=10;
397+
if (size<limit2)
398398
snprintf(VARDATA(result),50,INT64_FORMAT" MB",
399-
(size+mult /2) /mult);
399+
(size+1) /2);
400400
else
401401
{
402-
mult *=1024;
403-
if (size<limit*mult)
402+
size >>=10;
403+
if (size<limit2)
404404
snprintf(VARDATA(result),50,INT64_FORMAT" GB",
405-
(size+mult /2) /mult);
405+
(size+1) /2);
406406
else
407407
{
408-
/* Here we have to worry about avoiding overflow */
409-
int64val;
410-
411-
mult *=1024;
412-
val=size /mult;
413-
if ((size %mult) >= (mult /2))
414-
val++;
408+
size >>=10;
415409
snprintf(VARDATA(result),50,INT64_FORMAT" TB",
416-
val);
410+
(size+1) /2);
417411
}
418412
}
419413
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp