8000 witness: clean up Debug implementation by apoelstra · Pull Request #1942 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

witness: clean up Debug implementation #1942

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 1 commit into from
Jul 18, 2023
Merged

Conversation

apoelstra
Copy link
Member

The previous code seems to have been rebased/iterated on too many times, and had room for significant simplification. By inlining the indentation logic we can eliminate 40 LOC and also clean up the output by removing trailing spaces.

Fixes #1937

It is not good form to add unit tests for debug output but you can test this locally with the patch

diff --git a/bitcoin/src/blockdata/witness.rs b/bitcoin/src/blockdata/witness.rs
index d0b7408c..a2c38af0 100644
--- a/bitcoin/src/blockdata/witness.rs
+++ b/bitcoin/src/blockdata/witness.rs
@@ -619,6 +619,9 @@ mod test {
             "304402207c800d698f4b0298c5aac830b822f011bb02df41eb114ade9a6702f364d5e39c0220366900d2a60cab903e77ef7dd415d46509b1f78ac78906e3296f495aa1b1b54101")
             ];
         assert_eq!(witness.to_vec(), expected_witness);
+
+            println!("{:?}", witness);
+            panic!();
     }
 
     #[test]

And by sticking {:#?} in there to see the alternate output.

The previous code seems to have been rebased/iterated on too many times,
and had room for significant simplification. By inlining the indentation
logic we can eliminate 40 LOC and also clean up the output by removing
trailing spaces.
@tcharding
Copy link
Member

Ooooh that's what you meant, I was returning String from the helper functions causing allocation. I thought there was going to be some trickery for some obscure allocations :)

@tcharding
Copy link
Member

tACK e30c492

Copy link
Collaborator
@RCasatta RCasatta left a comment

Choose a reason for hiding this comment

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

ACK e30c492

@RCasatta RCasatta merged commit 28f6ad8 into master Jul 18, 2023
@apoelstra apoelstra deleted the 2023-07--allocate-debug branch July 18, 2023 18:31
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.

Remove allocations from Debug implementation of Witness
3 participants
0