Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map putchar('{char}') calls to printf '{char}` #130

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

laurenthuberdeau
Copy link
Collaborator

This saves a few seconds on dash, and makes the code easier to read. It compromises slightly from our principle of generating "regular" code without any special cases, but the original code looked bad and was harder to read so I think it's worth it.

This saves a few seconds on dash, and makes the code easier to read.
It compromises slightly from our principle of generating "regular" code
without any special cases, but the original code looked bad and was
harder to read so I think it's worth it.
@@ -84,15 +84,15 @@ _encode() {
printf \\$(((_$((_codes + (b1 >> 2))))/64))$(((_$((_codes + (b1 >> 2))))/8%8))$(((_$((_codes + (b1 >> 2))))%8))
if [ $b2 -lt 0 ] ; then
printf \\$(((_$((_codes + (63 & (b1 << 4)))))/64))$(((_$((_codes + (63 & (b1 << 4)))))/8%8))$(((_$((_codes + (63 & (b1 << 4)))))%8))
printf \\$(((__EQ__)/64))$(((__EQ__)/8%8))$(((__EQ__)%8))
printf \\$(((__EQ__)/64))$(((__EQ__)/8%8))$(((__EQ__)%8))
printf "="
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much shorter and easier to read!

@laurenthuberdeau laurenthuberdeau merged commit 5ac61e1 into main Jan 7, 2025
31 checks passed
@laurenthuberdeau laurenthuberdeau deleted the laurent/optimize-putchar-with-char-literal branch January 7, 2025 03:16
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.

1 participant