Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Issue 792043005: Remove run-time calculation of hash constants in pdfium. (Closed)

Created:
5 years, 11 months ago by brucedawson
Modified:
5 years, 11 months ago
Reviewers:
Tom Sepez, Lei Zhang
CC:
pdfium-reviews_googlegroups.com
Base URL:
https://pdfium.googlesource.com/pdfium.git@master
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Remove run-time calculation of hash constants in pdfium. PDFium static initializers must go. Static initializers are prohibited by the style guide. They have negative consequences including increased startup time (from pulling in additional code pages) and reduced sharing of data pages (since the variables can't go in the read-only data segment). This change uses a template struct and typed enums to reproduce JS_CalcHash at run-time. An unsigned long long constant and masking with 0xFFFFFFFF are used to avoid compile errors due to integer overflow of compile-time constants. The HashVerify class is used to check the results, necessary since none of the functions in global.cpp are called when pdfium_test.exe runs. const_expr would be a much cleaner way to implement this change but it is not yet widely supported. On the Windows release build this reduces the code size (.text virtual size) by 0x240 (576) bytes, the .data section by 0x20 bytes (for eight unsigned globals), and the .rdata section by 0x20 bytes (the unneeded string savings, minus the eight unsigned globals now being there). BUG=441899 R=tsepez@chromium.org Committed: https://pdfium.googlesource.com/pdfium/+/286ea1d88a41a670a17bd82d85a553c2df53c0c8

Patch Set 1 #

Total comments: 6

Patch Set 2 : Use variadic templates to remove hash limits. #

Total comments: 1

Patch Set 3 : Remove Pow class to simplify hashing. #

Total comments: 8

Patch Set 4 : Tweaks to the CHash class, and removing zeroes. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+66 lines, -8 lines) Patch
M fpdfsdk/src/javascript/global.cpp View 1 2 3 1 chunk +66 lines, -8 lines 0 comments Download

Messages

Total messages: 14 (2 generated)
Tom Sepez
+Lei for some c++ expertise. https://codereview.chromium.org/792043005/diff/1/fpdfsdk/src/javascript/global.cpp File fpdfsdk/src/javascript/global.cpp (right): https://codereview.chromium.org/792043005/diff/1/fpdfsdk/src/javascript/global.cpp#newcode21 fpdfsdk/src/javascript/global.cpp:21: template<const wchar_t A = ...
5 years, 11 months ago (2015-01-02 17:59:08 UTC) #3
brucedawson
I wrote an alternate implementation that uses variadic templates -- any thoughts on which is ...
5 years, 11 months ago (2015-01-02 19:56:18 UTC) #4
brucedawson
This change has been tested to ensure that it compiles with clang and that it ...
5 years, 11 months ago (2015-01-02 21:04:25 UTC) #5
Tom Sepez
https://codereview.chromium.org/792043005/diff/20001/fpdfsdk/src/javascript/global.cpp File fpdfsdk/src/javascript/global.cpp (right): https://codereview.chromium.org/792043005/diff/20001/fpdfsdk/src/javascript/global.cpp#newcode46 fpdfsdk/src/javascript/global.cpp:46: static const unsigned value = (N * Pow<Ns...>::value + ...
5 years, 11 months ago (2015-01-05 20:14:09 UTC) #6
brucedawson
I totally agree that the double recursion is ugly. I'm getting the hang of these ...
5 years, 11 months ago (2015-01-05 21:19:23 UTC) #7
Tom Sepez
On 2015/01/05 21:19:23, brucedawson wrote: > I totally agree that the double recursion is ugly. ...
5 years, 11 months ago (2015-01-05 21:22:09 UTC) #8
Tom Sepez
Me too. I was playing around with this because I was curious. https://codereview.chromium.org/792043005/diff/40001/fpdfsdk/src/javascript/global.cpp File fpdfsdk/src/javascript/global.cpp ...
5 years, 11 months ago (2015-01-05 21:26:20 UTC) #9
Tom Sepez
Howzabout: template <wchar_t... Ns> struct CHash; template <unsigned long long ACC, wchar_t... Ns> struct CHashHelper; ...
5 years, 11 months ago (2015-01-05 21:47:20 UTC) #10
brucedawson
Now it is perfect. https://codereview.chromium.org/792043005/diff/40001/fpdfsdk/src/javascript/global.cpp File fpdfsdk/src/javascript/global.cpp (right): https://codereview.chromium.org/792043005/diff/40001/fpdfsdk/src/javascript/global.cpp#newcode21 fpdfsdk/src/javascript/global.cpp:21: template <unsigned acc, wchar_t... Ns> ...
5 years, 11 months ago (2015-01-05 21:52:56 UTC) #11
brucedawson
It's an addictive intellectual puzzle isn't it? I'm inclined to prefer my solution -- four ...
5 years, 11 months ago (2015-01-05 21:58:15 UTC) #12
Tom Sepez
lgtm
5 years, 11 months ago (2015-01-05 22:00:27 UTC) #13
brucedawson
5 years, 11 months ago (2015-01-05 22:11:04 UTC) #14
Message was sent while issue was closed.
Committed patchset #4 (id:60001) manually as
286ea1d88a41a670a17bd82d85a553c2df53c0c8 (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698