Skip to content

Commit

Permalink
Windows: optimize binary size; don't embed translations hash table
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
strager committed Dec 8, 2021
1 parent 8063fc8 commit 408e7db
Show file tree
Hide file tree
Showing 7 changed files with 2,136 additions and 2,075 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ quick_lint_js_add_library(
quick-lint-js/cli-location.h
quick-lint-js/configuration-loader.h
quick-lint-js/configuration.h
quick-lint-js/consteval.h
quick-lint-js/cpp.h
quick-lint-js/crash.h
quick-lint-js/diagnostic-formatter.h
Expand Down
33 changes: 33 additions & 0 deletions src/quick-lint-js/consteval.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2020 Matthew "strager" Glazar
// See end of file for extended copyright information.

#ifndef QUICK_LINT_JS_CONSTEVAL_H
#define QUICK_LINT_JS_CONSTEVAL_H

#include <quick-lint-js/have.h>

#if QLJS_HAVE_CONSTEVAL
#define QLJS_CONSTEVAL consteval
#else
#define QLJS_CONSTEVAL constexpr
#endif

#endif

// quick-lint-js finds bugs in JavaScript programs.
// Copyright (C) 2020 Matthew "strager" Glazar
//
// This file is part of quick-lint-js.
//
// quick-lint-js is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// quick-lint-js is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
8 changes: 8 additions & 0 deletions src/quick-lint-js/have.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@
#define QLJS_HAVE_SIZED_ALIGNED_DELETE 0
#endif

#if !defined(QLJS_HAVE_CONSTEVAL)
#if defined(__cpp_consteval) && __cpp_consteval >= 201811L
#define QLJS_HAVE_CONSTEVAL 1
#else
#define QLJS_HAVE_CONSTEVAL 0
#endif
#endif

#endif

// quick-lint-js finds bugs in JavaScript programs.
Expand Down
Loading

0 comments on commit 408e7db

Please sign in to comment.