[x265] [PATCH] Minor sprintf optimization in ratecontrol.cpp

Adam Richter adamrichter4 at gmail.com
Sat May 18 15:33:40 CEST 2019


The attached patch against the Mercurial version of x265 attempts to
eliminate a tiny bit of unnecessary string rereading and writing in
the creation of a status message which I suspect is printed once per
video frame (involving ~8 calls to sprintf, I think), in the function
RateControl::writeRateControlFrameStats, which is in the file
x265/source/encoder/ratecontrol.cpp .

I happened to notice it the problem because I have been trying
cppcheck on various source trees, and it complained about some sprintf
calls in that function where the destination was also being passed as
an argument to "%s".  I think that practice may be safe because that
"%s" was the very first thing in the string, but once I looked at the
code, I got the itch to eliminate the unnecessary string rewriting and
memset calls.

I ran x265 --multi-pass-opt-rps --pass=1 to convert a video file and
got exactly the same x265_2pass.log file with and without this change.
The log file appeared to include ~4800 lines containing the effected
messages (so, x4 = 38,400 sprintf calls?).

Please note that I am not an x265 developer, and this is my first
attempt at submitting an x265 patch.  So, please feel free to let me
know if I should be following a different process.  If nobody tells me
to do otherwise and if there are no complaints about this patch on
this mailing list in the next couple of days, I guess I will submit it
to x265Contributions at multicorewareinc.com.

I submit the attached Contribution under the terms of the
MulticoreWre, Inc. x265 Contributor Agreement.

Adam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x265-sprintf.diff
Type: application/x-patch
Size: 1033 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20190518/7b16c249/attachment.bin>


More information about the x265-devel mailing list