| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 522a30f commit a612ecb
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | ||
| 37 | 37 | # Reset this number to 0 on major V8 upgrades. | |
| 38 | 38 | # Increment by one for each non-official patch applied to deps/v8. | |
| 39 | - 'v8_embedder_string': '-node.13', | ||
| 39 | + 'v8_embedder_string': '-node.14', | ||
| 40 | 40 | ||
| 41 | 41 | ##### V8 defaults for Node.js ##### | |
| 42 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1889,17 +1889,28 @@ bool IsSwitchOptimizable(SwitchStatement* stmt, SwitchInfo* info) { | |||
| 1889 | 1889 | } | |
| 1890 | 1890 | ||
| 1891 | 1891 | // GCC also jump-table optimizes switch statements with 6 cases or more. | |
| 1892 | - if (!(static_cast<int>(info->covered_cases.size()) >= | ||
| 1893 | - FLAG_switch_table_min_cases && | ||
| 1894 | - IsSpreadAcceptable(info->MaxCase() - info->MinCase(), | ||
| 1895 | - cases->length()))) { | ||
| 1896 | - // Invariant- covered_cases has all cases and only cases that will go in the | ||
| 1897 | - // jump table. | ||
| 1898 | - info->covered_cases.clear(); | ||
| 1899 | - return false; | ||
| 1900 | - } else { | ||
| 1901 | - return true; | ||
| 1902 | - } | ||
| 1892 | + if (static_cast<int>(info->covered_cases.size()) >= | ||
| 1893 | + FLAG_switch_table_min_cases) { | ||
| 1894 | + // Due to case spread will be used as the size of jump-table, | ||
| 1895 | + // we need to check if it doesn't overflow by casting its | ||
| 1896 | + // min and max bounds to int64_t, and calculate if the difference is less | ||
| 1897 | + // than or equal to INT_MAX. | ||
| 1898 | + int64_t min = static_cast<int64_t>(info->MinCase()); | ||
| 1899 | + int64_t max = static_cast<int64_t>(info->MaxCase()); | ||
| 1900 | + int64_t spread = max - min + 1; | ||
| 1901 | + | ||
| 1902 | + DCHECK_GT(spread, 0); | ||
| 1903 | + | ||
| 1904 | + // Check if casted spread is acceptable and doesn't overflow. | ||
| 1905 | + if (spread <= INT_MAX && | ||
| 1906 | + IsSpreadAcceptable(static_cast<int>(spread), cases->length())) { | ||
| 1907 | + return true; | ||
| 1908 | + } | ||
| 1909 | + } | ||
| 1910 | + // Invariant- covered_cases has all cases and only cases that will go in the | ||
| 1911 | + // jump table. | ||
| 1912 | + info->covered_cases.clear(); | ||
| 1913 | + return false; | ||
| 1903 | 1914 | } | |
| 1904 | 1915 | ||
| 1905 | 1916 | } // namespace | |
| Back | FazBrowse Home | New Git URL |
0 commit comments