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

Commit9f1ca6c

Browse files
committed
Use appendStringInfoSpaces in more places
This adjusts a few places which were appending a string constantcontaining spaces onto a StringInfo. We have appendStringInfoSpaces forthat job, so let's use that instead.For the change to jsonb.c's add_indent() function, appendStringInfoStringwas being called inside a loop to append 4 spaces on each loop. Thismeant that enlargeStringInfo would get called once per loop. Here itshould be much more efficient to get rid of the loop and just calculatethe number of spaces with "level * 4" and just append all the spaces inone go.Here we additionally adjust the appendStringInfoSpaces function so itmakes use of memset rather than a while loop to apply the required spacesto the StringInfo. One of the problems with the while loop was that itwas incrementing one variable and decrementing another variable once perloop. That's more work than what's required to get the job done. We mayas well use memset for this rather than trying to optimize the existingloop. Some testing has shown memset is faster even for very small sizes.Discussion:https://postgr.es/m/CAApHDvp_rKkvwudBKgBHniNRg67bzXVjyvVKfX0G2zS967K43A@mail.gmail.com
1 parent1ca604c commit9f1ca6c

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

‎src/backend/commands/explain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3324,7 +3324,7 @@ show_hashagg_info(AggState *aggstate, ExplainState *es)
33243324
if (!gotone)
33253325
ExplainIndentText(es);
33263326
else
3327-
appendStringInfoString(es->str," ");
3327+
appendStringInfoSpaces(es->str,2);
33283328

33293329
appendStringInfo(es->str,"Batches: %d Memory Usage: "INT64_FORMAT"kB",
33303330
aggstate->hash_batches_used,memPeakKb);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,8 @@ add_indent(StringInfo out, bool indent, int level)
626626
{
627627
if (indent)
628628
{
629-
inti;
630-
631629
appendStringInfoCharMacro(out,'\n');
632-
for (i=0;i<level;i++)
633-
appendBinaryStringInfo(out," ",4);
630+
appendStringInfoSpaces(out,level*4);
634631
}
635632
}
636633

‎src/common/stringinfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ appendStringInfoSpaces(StringInfo str, int count)
211211
enlargeStringInfo(str,count);
212212

213213
/* OK, append the spaces */
214-
while (--count >=0)
215-
str->data[str->len++]=' ';
214+
memset(&str->data[str->len],' ',count);
215+
str->len+=count;
216216
str->data[str->len]='\0';
217217
}
218218
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp