Skip to content

feat(#4752): add reusable tt converters for sprintf#5272

Merged
yegor256 merged 4 commits into
objectionary:masterfrom
asmirnov-backend:4752-tt-converters
Jun 29, 2026
Merged

feat(#4752): add reusable tt converters for sprintf#5272
yegor256 merged 4 commits into
objectionary:masterfrom
asmirnov-backend:4752-tt-converters

Conversation

@asmirnov-backend

@asmirnov-backend asmirnov-backend commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Part of #4752. Prerequisite for #5271.

Adds four small, independently tested tt objects that render numbers and bytes as text:

  • as-char — ASCII code (0-255) → single byte, the inverse of as-ascii
  • as-decimal — number → signed decimal digits, truncating toward zero
  • as-hex — bytes → uppercase hexadecimal pairs joined by a hyphen
  • as-fixed — number → fixed-point decimal with a chosen number of fraction digits, rounded

Why

Without these objects, tt.sprintf (#5271) carries a lot of internal methods — dec, digits, one-digit, flt, positive, rec-pad, hex, rec-hex, hex-digit — and becomes complicated to read. Extracting them into focused, reusable objects (mirroring the existing as-ascii and is-digit) keeps each concern small and lets sprintf compose them instead of inlining everything.

Once this is merged, #5271 is rebased to drop the inline formatters and use these objects directly.

asmirnov-backend and others added 4 commits June 27, 2026 14:09
Write an ASCII code (0-255) as its single byte, the inverse of `as-ascii`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Write a number as signed decimal digits, truncating its fraction toward zero.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Write bytes as uppercase hexadecimal pairs joined by a hyphen.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Write a number as fixed-point decimal with a chosen number of fraction
digits, rounding to the nearest unit in the last place.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Performance Analysis

All benchmarks are within the acceptable range. No critical degradation detected (threshold is 100%). Please refer to the detailed report for more information.

Click to see the detailed report
Test Base Score PR Score Change % Change Unit Mode
benchmarks.XmirBench.xmirToEO 10984.985 10874.907 -110.078 -1.00% ms/op Average Time

✅ Performance gain: benchmarks.XmirBench.xmirToEO is faster by 110.078 ms/op (1.00%)

@asmirnov-backend
asmirnov-backend marked this pull request as ready for review June 27, 2026 16:31
@asmirnov-backend

Copy link
Copy Markdown
Contributor Author

@yegor256, could you please take a look

@yegor256
yegor256 merged commit f10e8ce into objectionary:master Jun 29, 2026
26 checks passed
@sonarqubecloud

Copy link
Copy Markdown

@0crat

0crat commented Jun 29, 2026

Copy link
Copy Markdown

@asmirnov-backend Thanks for the contribution! You've earned +12 points for this: +16 as a basis; -4 for too many hits-of-code (266 >= 100). Please, keep them coming. Your running score is +144; don't forget to check your Zerocracy account too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants