Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving performance, using caching when testing for primitives (#6252) #6253

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toSet;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

Expand All @@ -69,6 +73,7 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo
private final VersionCanonicalizer myVersionCanonicalizer;
private final LoadingCache<ResourceKey, IBaseResource> myFetchResourceCache;
private volatile List<StructureDefinition> myAllStructures;
private volatile Set<String> myAllPrimitiveTypes;
private Parameters myExpansionProfile;

public VersionSpecificWorkerContextWrapper(
Expand Down Expand Up @@ -617,11 +622,23 @@ public List<StructureDefinition> fetchTypeDefinitions(String theTypeName, FhirPu

@Override
public boolean isPrimitiveType(String theType) {
List<StructureDefinition> allStructures = new ArrayList<>(allStructures());
return allStructures.stream()
.filter(structureDefinition ->
structureDefinition.getKind() == StructureDefinition.StructureDefinitionKind.PRIMITIVETYPE)
.anyMatch(structureDefinition -> theType.equals(structureDefinition.getName()));
return allPrimitiveTypes().contains(theType);
}

private Set<String> allPrimitiveTypes() {
Set<String> retVal = myAllPrimitiveTypes;
if (retVal == null) {
// Collector may be changed to Collectors.toUnmodifiableSet() when switching to Android API level >= 33
retVal = allStructures().stream()
.filter(structureDefinition ->
structureDefinition.getKind() == StructureDefinition.StructureDefinitionKind.PRIMITIVETYPE)
.map(StructureDefinition::getName)
.filter(Objects::nonNull)
.collect(collectingAndThen(toSet(), Collections::unmodifiableSet));
myAllPrimitiveTypes = retVal;
}

return retVal;
}

@Override
Expand Down
Loading