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

Change javap function to write to writer #7

Open
ExcaliburZero opened this issue Jan 9, 2021 · 1 comment
Open

Change javap function to write to writer #7

ExcaliburZero opened this issue Jan 9, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@ExcaliburZero
Copy link
Owner

As of #5, in the main javap function we write the program output to a string and then at the end return that string to be printed all at once. This has the advantage of being very testable, but repeated string concatenation can potentially lead to performance issues due to repeated reallocation of increasingly larger strings.

So we should change the javap function to take in a writer as an argument and have it write all the program output to the writer. This would allow us to pass in stdout for the executable, and for the tests use a dummy writer that could convert the output to a string to test using an assertion.

We could also instead create a OutputStreams struct that serves this purpose, while allowing for working with both stdout and stderr. Currently we only write out to stdout, but it would be nice to also have the capability to write to stderr if we want to provide any user-targeted error messages.

@ExcaliburZero ExcaliburZero added the enhancement New feature or request label Jan 9, 2021
@ExcaliburZero
Copy link
Owner Author

Relevant code section:

fn javap(filepath: &str, print_code: bool) -> String {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant