Simply add spaces to the existing string instead of using a temporary.
Fixes #4756.
Tested with src/bitcoin-tx -json -create.
74 | - 75 | -static string indentStr(unsigned int prettyIndent, unsigned int indentLevel) 76 | +static void indentStr(unsigned int prettyIndent, unsigned int indentLevel, string& s) 77 | { 78 | unsigned int spaces = prettyIndent * indentLevel; 79 | - while (spaceStr.size() < spaces)
This seems to be more than just using a copy?
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)
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 += ' '?
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.
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 #4756.
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4851_41ef558aa907c50a055c44c4e6abaf813b23aeff/ for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.
Untested ACK
ut ACK -- nice improvement