-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Cut down on number formating code size #58272
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da5a0cd
De-duplicate number formatting implementations for smaller code size
fitzgen ed2157a
De-duplicate write_prefix lambda in pad_integral
fitzgen e633f15
Un-monomorphize and inline formatting with padding
fitzgen c104b5c
Also de-duplicate 32- and 64-bit number formatting on wasm32
fitzgen 05df9ff
Add a wasm code size test for stringifying numbers
fitzgen 8fea705
Use write_char for writing padding characters
fitzgen f00f0e6
Don't shadow the provided `stringify!` macro in a wasm code size test…
fitzgen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add a wasm code size test for stringifying numbers
- Loading branch information
commit 05df9ff41537bab6586eea7ad9272eeb611e09e1
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| -include ../../run-make-fulldeps/tools.mk | ||
|
|
||
| ifeq ($(TARGET),wasm32-unknown-unknown) | ||
| all: | ||
| $(RUSTC) foo.rs -C lto -O --target wasm32-unknown-unknown | ||
| wc -c < $(TMPDIR)/foo.wasm | ||
| [ "`wc -c < $(TMPDIR)/foo.wasm`" -lt "21000" ] | ||
| else | ||
| all: | ||
| endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #![crate_type = "cdylib"] | ||
|
|
||
| extern "C" { | ||
| fn observe(ptr: *const u8, len: usize); | ||
|
|
||
| fn get_u8() -> u8; | ||
| fn get_i8() -> i8; | ||
| fn get_u16() -> u16; | ||
| fn get_i16() -> i16; | ||
| fn get_u32() -> u32; | ||
| fn get_i32() -> i32; | ||
| fn get_u64() -> u64; | ||
| fn get_i64() -> i64; | ||
| fn get_usize() -> usize; | ||
| fn get_isize() -> isize; | ||
| } | ||
|
|
||
| macro_rules! stringify { | ||
| ( $($f:ident)* ) => { | ||
| $( | ||
| let s = $f().to_string(); | ||
| observe(s.as_ptr(), s.len()); | ||
| )* | ||
| }; | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| pub unsafe extern "C" fn foo() { | ||
| stringify!(get_u8); | ||
| stringify!(get_i8); | ||
| stringify!(get_u16); | ||
| stringify!(get_i16); | ||
| stringify!(get_u32); | ||
| stringify!(get_i32); | ||
| stringify!(get_u64); | ||
| stringify!(get_i64); | ||
| stringify!(get_usize); | ||
| stringify!(get_isize); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.