univalue: make spaceStr thread-safe#4851
Conversation
src/univalue/univalue_write.cpp
Outdated
There was a problem hiding this comment.
This seems to be more than just using a copy?
There was a problem hiding this comment.
I don't get where this idea comes from. Why would copying be cheaper than just generating spaces on the fly? Memory access is much slower than (trivial) computation.
And what do you think a copy does internally? (not to say the temporary generated by substr)
There was a problem hiding this comment.
Sorry wrong wording perhaps, let me try again. You are now using a reference, but what is done in this function now looks a little different. See the long space line in the diff and now just s += ' '?
There was a problem hiding this comment.
Oh I see what you mean now. But it seems correct: the old loop adds spaces in units of 16 and then does a substring, but there is no point in doing that in the new case which only adds as many spaces as requested.
There was a problem hiding this comment.
Looking at the std::string API there seems to be an even better way:
string.append(spaces, ' ');
Gotta test this :)
|
ut ACK |
Simply add spaces to the existing string instead of using a temporary. Fixes bitcoin#4756.
92a7533 to
41ef558
Compare
|
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4851_41ef558aa907c50a055c44c4e6abaf813b23aeff/ for binaries and test log. |
|
Untested ACK |
|
ut ACK -- nice improvement |
41ef558 univalue: make spaceStr thread-safe (Wladimir J. van der Laan)
Simply add spaces to the existing string instead of using a temporary.
Fixes #4756.
Tested with
src/bitcoin-tx -json -create.