Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f8acf2d

Browse filesBrowse files
jasnelladuh95
authored andcommitted
src: make minor cleanups in compile_cache.cc
PR-URL: #57448 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 0583c3d commit f8acf2d
Copy full SHA for f8acf2d

File tree

Expand file treeCollapse file tree

1 file changed

+30
-24
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+30
-24
lines changed
Open diff view settings
Collapse file

‎src/compile_cache.cc‎

Copy file name to clipboardExpand all lines: src/compile_cache.cc
+30-24Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
#endif
1515

1616
namespace node {
17+
18+
using v8::Function;
19+
using v8::Local;
20+
using v8::Module;
21+
using v8::ScriptCompiler;
22+
using v8::String;
23+
24+
namespace {
1725
std::string Uint32ToHex(uint32_t crc) {
1826
std::string str;
1927
str.reserve(8);
@@ -40,8 +48,7 @@ std::string GetCacheVersionTag() {
4048
// This should be fine on Windows, as there local directories tend to be
4149
// user-specific.
4250
std::string tag = std::string(NODE_VERSION) + '-' + std::string(NODE_ARCH) +
43-
'-' +
44-
Uint32ToHex(v8::ScriptCompiler::CachedDataVersionTag());
51+
'-' + Uint32ToHex(ScriptCompiler::CachedDataVersionTag());
4552
#ifdef NODE_IMPLEMENTS_POSIX_CREDENTIALS
4653
tag += '-' + std::to_string(getuid());
4754
#endif
@@ -55,6 +62,7 @@ uint32_t GetCacheKey(std::string_view filename, CachedCodeType type) {
5562
crc, reinterpret_cast<const Bytef*>(filename.data()), filename.length());
5663
return crc;
5764
}
65+
} // namespace
5866

5967
template <typename... Args>
6068
inline void CompileCacheHandler::Debug(const char* format,
@@ -64,13 +72,13 @@ inline void CompileCacheHandler::Debug(const char* format,
6472
}
6573
}
6674

67-
v8::ScriptCompiler::CachedData* CompileCacheEntry::CopyCache() const {
75+
ScriptCompiler::CachedData* CompileCacheEntry::CopyCache() const {
6876
DCHECK_NOT_NULL(cache);
6977
int cache_size = cache->length;
7078
uint8_t* data = new uint8_t[cache_size];
7179
memcpy(data, cache->data, cache_size);
72-
return new v8::ScriptCompiler::CachedData(
73-
data, cache_size, v8::ScriptCompiler::CachedData::BufferOwned);
80+
return new ScriptCompiler::CachedData(
81+
data, cache_size, ScriptCompiler::CachedData::BufferOwned);
7482
}
7583

7684
// Used for identifying and verifying a file is a compile cache file.
@@ -210,15 +218,14 @@ void CompileCacheHandler::ReadCacheFile(CompileCacheEntry* entry) {
210218
return;
211219
}
212220

213-
entry->cache.reset(new v8::ScriptCompiler::CachedData(
214-
buffer, total_read, v8::ScriptCompiler::CachedData::BufferOwned));
221+
entry->cache.reset(new ScriptCompiler::CachedData(
222+
buffer, total_read, ScriptCompiler::CachedData::BufferOwned));
215223
Debug(" success, size=%d\n", total_read);
216224
}
217225

218-
CompileCacheEntry* CompileCacheHandler::GetOrInsert(
219-
v8::Local<v8::String> code,
220-
v8::Local<v8::String> filename,
221-
CachedCodeType type) {
226+
CompileCacheEntry* CompileCacheHandler::GetOrInsert(Local<String> code,
227+
Local<String> filename,
228+
CachedCodeType type) {
222229
DCHECK(!compile_cache_dir_.empty());
223230

224231
Utf8Value filename_utf8(isolate_, filename);
@@ -259,18 +266,17 @@ CompileCacheEntry* CompileCacheHandler::GetOrInsert(
259266
return result;
260267
}
261268

262-
v8::ScriptCompiler::CachedData* SerializeCodeCache(
263-
v8::Local<v8::Function> func) {
264-
return v8::ScriptCompiler::CreateCodeCacheForFunction(func);
269+
ScriptCompiler::CachedData* SerializeCodeCache(Local<Function> func) {
270+
return ScriptCompiler::CreateCodeCacheForFunction(func);
265271
}
266272

267-
v8::ScriptCompiler::CachedData* SerializeCodeCache(v8::Local<v8::Module> mod) {
268-
return v8::ScriptCompiler::CreateCodeCache(mod->GetUnboundModuleScript());
273+
ScriptCompiler::CachedData* SerializeCodeCache(Local<Module> mod) {
274+
return ScriptCompiler::CreateCodeCache(mod->GetUnboundModuleScript());
269275
}
270276

271277
template <typename T>
272278
void CompileCacheHandler::MaybeSaveImpl(CompileCacheEntry* entry,
273-
v8::Local<T> func_or_mod,
279+
Local<T> func_or_mod,
274280
bool rejected) {
275281
DCHECK_NOT_NULL(entry);
276282
Debug("[compile cache] V8 code cache for %s %s was %s, ",
@@ -286,21 +292,21 @@ void CompileCacheHandler::MaybeSaveImpl(CompileCacheEntry* entry,
286292
Debug("%s the in-memory entry\n",
287293
entry->cache == nullptr ? "initializing" : "refreshing");
288294

289-
v8::ScriptCompiler::CachedData* data = SerializeCodeCache(func_or_mod);
290-
DCHECK_EQ(data->buffer_policy, v8::ScriptCompiler::CachedData::BufferOwned);
295+
ScriptCompiler::CachedData* data = SerializeCodeCache(func_or_mod);
296+
DCHECK_EQ(data->buffer_policy, ScriptCompiler::CachedData::BufferOwned);
291297
entry->refreshed = true;
292298
entry->cache.reset(data);
293299
}
294300

295301
void CompileCacheHandler::MaybeSave(CompileCacheEntry* entry,
296-
v8::Local<v8::Module> mod,
302+
Local<Module> mod,
297303
bool rejected) {
298304
DCHECK(mod->IsSourceTextModule());
299305
MaybeSaveImpl(entry, mod, rejected);
300306
}
301307

302308
void CompileCacheHandler::MaybeSave(CompileCacheEntry* entry,
303-
v8::Local<v8::Function> func,
309+
Local<Function> func,
304310
bool rejected) {
305311
MaybeSaveImpl(entry, func, rejected);
306312
}
@@ -319,8 +325,8 @@ void CompileCacheHandler::MaybeSave(CompileCacheEntry* entry,
319325
int cache_size = static_cast<int>(transpiled.size());
320326
uint8_t* data = new uint8_t[cache_size];
321327
memcpy(data, transpiled.data(), cache_size);
322-
entry->cache.reset(new v8::ScriptCompiler::CachedData(
323-
data, cache_size, v8::ScriptCompiler::CachedData::BufferOwned));
328+
entry->cache.reset(new ScriptCompiler::CachedData(
329+
data, cache_size, ScriptCompiler::CachedData::BufferOwned));
324330
entry->refreshed = true;
325331
}
326332

@@ -377,7 +383,7 @@ void CompileCacheHandler::Persist() {
377383
}
378384

379385
DCHECK_EQ(entry->cache->buffer_policy,
380-
v8::ScriptCompiler::CachedData::BufferOwned);
386+
ScriptCompiler::CachedData::BufferOwned);
381387
char* cache_ptr =
382388
reinterpret_cast<char*>(const_cast<uint8_t*>(entry->cache->data));
383389
uint32_t cache_size = static_cast<uint32_t>(entry->cache->length);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.