- Notifications
You must be signed in to change notification settings - Fork28
Commitabd9ca3
committed
Make assorted performance improvements in snprintf.c.
In combination, these changes make our version of snprintf as fastor faster than most platforms' native snprintf, except for casesinvolving floating-point conversion (which we still delegate tothe native sprintf). The speed penalty for a float conversionis down to around 10% though, much better than before.Notable changes:* Rather than always parsing the format twice to see if it containsinstances of %n$, do the extra scan only if we actually find a $.This obviously wins for non-localized formats, and even when thereis use of %n$, we can avoid scanning text before the first % twice.* Use strchrnul() if available to find the next %, and emit theliteral text between % escapes as strings rather than char-by-char.* Create a bespoke function (dopr_outchmulti) for the common caseof emitting N copies of the same character, in place of writingloops around dopr_outch.* Simplify construction of the format string for invocations of sprintffor floats.* Const-ify some internal functions, and avoid unnecessary use ofpass-by-reference arguments.Patch by me, reviewed by Andres FreundDiscussion:https://postgr.es/m/11787.1534530779@sss.pgh.pa.us1 parent9bc9f72 commitabd9ca3
File tree
5 files changed
+432
-273
lines changed- src
- include
- port
5 files changed
+432
-273
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15100 | 15100 | | |
15101 | 15101 | | |
15102 | 15102 | | |
15103 | | - | |
| 15103 | + | |
15104 | 15104 | | |
15105 | 15105 | | |
15106 | 15106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1571 | 1571 | | |
1572 | 1572 | | |
1573 | 1573 | | |
1574 | | - | |
| 1574 | + | |
1575 | 1575 | | |
1576 | 1576 | | |
1577 | 1577 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
526 | 529 | | |
527 | 530 | | |
528 | 531 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
397 | 400 | | |
398 | 401 | | |
399 | 402 | | |
| |||
0 commit comments
Comments
(0)