Ignore:
Timestamp:
2024-04-16T15:58:38+02:00 (7 months ago)
Author:
taylor.smock
Message:

Cache record component accesses in FIT plugin to reduce CPU cost

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/FitPlugin.java

    r36158 r36248  
    1111import java.util.Arrays;
    1212import java.util.Collections;
     13import java.util.HashMap;
    1314import java.util.TreeMap;
    1415import java.util.concurrent.TimeUnit;
     
    5556        @Override
    5657        public void importData(File file, ProgressMonitor progressMonitor) throws IOException {
     58            final var fieldMap = new HashMap<Class<? extends Record>, RecordComponent[]>(1);
    5759            try (var inputStream = Files.newInputStream(file.toPath())) {
    5860                final var records = FitReader.read(inputStream, FitReaderOptions.TRY_TO_FINISH);
     
    7375                            // Use a sorted map for consistency
    7476                            final var map = new TreeMap<String, Object>();
    75                             for (RecordComponent component : HeartRateCadenceDistanceSpeed.class
    76                                     .getRecordComponents()) {
     77                            for (RecordComponent component : fieldMap.computeIfAbsent(HeartRateCadenceDistanceSpeed.class,
     78                                    Class::getRecordComponents)) {
    7779                                if (Arrays.asList("lat", "lon", "timestamp", "unknown").contains(component.getName())) {
    7880                                    continue; // skip information that has specific fields
Note: See TracChangeset for help on using the changeset viewer.