Skip to content

Commit 408e7db

Browse files
committed
Windows: optimize binary size; don't embed translations hash table
The MSVC toolchain is embedding translation_table_const_hash_table into the .exe file. (Other toolchains seem to not embed the table into the final executable.) The whole point of translation_table_const_hash_table is that it should not be embedded. Tweak translation_table_const_hash_table to be declared in a consteval function. This forces the compiler to evaluate it at compile time only. This seems to remove the table from the Windows .exe, shrinking the .exe significantly. This commit should not change behavior.
1 parent 8063fc8 commit 408e7db

7 files changed

Lines changed: 2136 additions & 2075 deletions

File tree

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ quick_lint_js_add_library(
104104
quick-lint-js/cli-location.h
105105
quick-lint-js/configuration-loader.h
106106
quick-lint-js/configuration.h
107+
quick-lint-js/consteval.h
107108
quick-lint-js/cpp.h
108109
quick-lint-js/crash.h
109110
quick-lint-js/diagnostic-formatter.h

src/quick-lint-js/consteval.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (C) 2020 Matthew "strager" Glazar
2+
// See end of file for extended copyright information.
3+
4+
#ifndef QUICK_LINT_JS_CONSTEVAL_H
5+
#define QUICK_LINT_JS_CONSTEVAL_H
6+
7+
#include <quick-lint-js/have.h>
8+
9+
#if QLJS_HAVE_CONSTEVAL
10+
#define QLJS_CONSTEVAL consteval
11+
#else
12+
#define QLJS_CONSTEVAL constexpr
13+
#endif
14+
15+
#endif
16+
17+
// quick-lint-js finds bugs in JavaScript programs.
18+
// Copyright (C) 2020 Matthew "strager" Glazar
19+
//
20+
// This file is part of quick-lint-js.
21+
//
22+
// quick-lint-js is free software: you can redistribute it and/or modify
23+
// it under the terms of the GNU General Public License as published by
24+
// the Free Software Foundation, either version 3 of the License, or
25+
// (at your option) any later version.
26+
//
27+
// quick-lint-js is distributed in the hope that it will be useful,
28+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+
// GNU General Public License for more details.
31+
//
32+
// You should have received a copy of the GNU General Public License
33+
// along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

src/quick-lint-js/have.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,14 @@
402402
#define QLJS_HAVE_SIZED_ALIGNED_DELETE 0
403403
#endif
404404

405+
#if !defined(QLJS_HAVE_CONSTEVAL)
406+
#if defined(__cpp_consteval) && __cpp_consteval >= 201811L
407+
#define QLJS_HAVE_CONSTEVAL 1
408+
#else
409+
#define QLJS_HAVE_CONSTEVAL 0
410+
#endif
411+
#endif
412+
405413
#endif
406414

407415
// quick-lint-js finds bugs in JavaScript programs.

0 commit comments

Comments
 (0)