Skip to content

Commit 0911b46

Browse files
authored
Only generate one PathScript if 2 or more are in the same source file. (#810)
1 parent 1b0a835 commit 0911b46

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/script/jvm_script_manager.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ void JvmScriptManager::create_and_update_scripts(Vector<KtClass*>& classes) {
6464
// ####PATH SCRIPT#######
6565
script_path = RES_DIRECTORY + kotlin_class->relative_source_path;
6666
// We check if the file even exist, the KtClass can come from a library or module.
67-
if (FileAccess::exists(script_path)) {
67+
// We also verify if that path is not already in cache, in case several registered classes are in the same file. We only create a script for the first one.
68+
if (FileAccess::exists(script_path) && !filepath_to_name_map.has(script_path)) {
6869
name_to_filepath_map[kotlin_class->registered_class_name] = script_path;
6970
filepath_to_name_map[script_path] = kotlin_class->registered_class_name;
7071

@@ -73,10 +74,10 @@ void JvmScriptManager::create_and_update_scripts(Vector<KtClass*>& classes) {
7374
// Try to find if a matching PathScript exist
7475
if (name_to_filepath_cache.has(script_name)) {
7576
// First we try using the path in cache. Necessary if the Kotlin file has been moved since the previous loading.
76-
script_path = name_to_filepath_cache[script_name];// Use the old path so we can properly remove its entry in the cache.
77+
script_path = name_to_filepath_cache[script_name]; // Use the old path so we can properly remove its entry in the cache.
7778
path_script = path_script_cache[script_path];
7879
} else if (path_script_cache.has(script_path)) {
79-
// Second we try with the name provided by the KtClass directly;
80+
// Second we try with the path provided by the KtClass directly;
8081
path_script = path_script_cache[script_path];
8182
}
8283

0 commit comments

Comments
 (0)