From 8a1e93f1ba49fb784fc9dbbadc6b1855588629eb Mon Sep 17 00:00:00 2001 From: smilefx Date: Fri, 26 Apr 2024 11:24:34 +0200 Subject: [PATCH 1/3] Added cache to static data files --- .../importer/carla/carlaDataFileHandling.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt b/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt index 7d549d8d..2f3084f6 100644 --- a/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt +++ b/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt @@ -147,8 +147,20 @@ fun loadSegments( simulationRunsWrapperList = sortedSimulationRunsWrapperList } - // Load Blocks and save in SimulationRunsWrapper - simulationRunsWrapperList.forEach { it.blocks = loadBlocks(it.mapDataFile).toList() } + // Holds the static blocks for each map file name + val staticBlockCache = mutableMapOf>() + + // Load Blocks and save in cache for each map file name + simulationRunsWrapperList.forEach { + // Check if static blocks for static map file name are already loaded + if (!staticBlockCache.containsKey(it.mapDataFile.toString())) { + // Load blocks and save in cache + staticBlockCache[it.mapDataFile.toString()] = loadBlocks(it.mapDataFile).toList() + } + + // Set blocks for current simulationRunsWrapper from the 'cache' + it.blocks = staticBlockCache[it.mapDataFile.toString()]!! + } // Holds the [ArrayDeque] of [CarlaSimulationRunsWrapper] from the parameters val simulationRunsWrappersDeque = ArrayDeque(simulationRunsWrapperList) From eb10d2581f4f44ff29503d2e8d6584cb3576a19e Mon Sep 17 00:00:00 2001 From: smilefx Date: Fri, 26 Apr 2024 11:29:55 +0200 Subject: [PATCH 2/3] Fixed indentation --- .../tools/aqua/stars/importer/carla/carlaDataFileHandling.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt b/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt index 2f3084f6..e0ed9200 100644 --- a/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt +++ b/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt @@ -155,7 +155,7 @@ fun loadSegments( // Check if static blocks for static map file name are already loaded if (!staticBlockCache.containsKey(it.mapDataFile.toString())) { // Load blocks and save in cache - staticBlockCache[it.mapDataFile.toString()] = loadBlocks(it.mapDataFile).toList() + staticBlockCache[it.mapDataFile.toString()] = loadBlocks(it.mapDataFile).toList() } // Set blocks for current simulationRunsWrapper from the 'cache' From 53b84f80807471729e29a28dd9f5cfbc8ea06226 Mon Sep 17 00:00:00 2001 From: smilefx Date: Mon, 13 May 2024 20:10:27 +0200 Subject: [PATCH 3/3] Improved code quality using map function --- .../aqua/stars/importer/carla/carlaDataFileHandling.kt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt b/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt index e0ed9200..d76f31ee 100644 --- a/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt +++ b/stars-importer-carla/src/main/kotlin/tools/aqua/stars/importer/carla/carlaDataFileHandling.kt @@ -152,14 +152,8 @@ fun loadSegments( // Load Blocks and save in cache for each map file name simulationRunsWrapperList.forEach { - // Check if static blocks for static map file name are already loaded - if (!staticBlockCache.containsKey(it.mapDataFile.toString())) { - // Load blocks and save in cache - staticBlockCache[it.mapDataFile.toString()] = loadBlocks(it.mapDataFile).toList() - } - - // Set blocks for current simulationRunsWrapper from the 'cache' - it.blocks = staticBlockCache[it.mapDataFile.toString()]!! + it.blocks = + staticBlockCache.getOrPut(it.mapDataFile.toString()) { loadBlocks(it.mapDataFile).toList() } } // Holds the [ArrayDeque] of [CarlaSimulationRunsWrapper] from the parameters