From 6cc8fe96ed0895cae9896f8ca292075876c834ed Mon Sep 17 00:00:00 2001 From: Ladislav Borak Date: Tue, 9 Dec 2014 12:32:24 +0100 Subject: [PATCH] Bug 2287 - TypeProviderImpl retains empty HashMaps Allocating default HashMaps is wasteful, especially if we end up not storing anything in them. This fixes that case by making sure we allocate a map only after we are sure we are going to put something into it. Also be conservative about the size, so we do not waste too much space. Change-Id: I85ad1506e732a5c3728ef3529e7e0b5b430d758a Signed-off-by: Ladislav Borak Signed-off-by: Robert Varga --- .../sal/binding/yang/types/TypeProviderImpl.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java b/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java index b393c13367..11edd05925 100644 --- a/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java +++ b/code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java @@ -621,7 +621,7 @@ public final class TypeProviderImpl implements TypeProvider { */ private void resolveTypeDefsFromContext() { final Set modules = schemaContext.getModules(); - Preconditions.checkArgument(modules != null, "Sef of Modules cannot be NULL!"); + Preconditions.checkArgument(modules != null, "Set of Modules cannot be NULL!"); final Module[] modulesArray = new Module[modules.size()]; int i = 0; for (Module modul : modules) { @@ -635,8 +635,7 @@ public final class TypeProviderImpl implements TypeProvider { if (dateTypeMap == null) { dateTypeMap = new HashMap<>(); } - final Map typeMap = new HashMap<>(); - dateTypeMap.put(module.getRevision(), typeMap); + dateTypeMap.put(module.getRevision(), Collections.emptyMap()); genTypeDefsContextMap.put(module.getName(), dateTypeMap); } @@ -731,8 +730,12 @@ public final class TypeProviderImpl implements TypeProvider { } if (returnType != null) { final Map> modulesByDate = genTypeDefsContextMap.get(moduleName); - final Map typeMap = modulesByDate.get(moduleRevision); + Map typeMap = modulesByDate.get(moduleRevision); if (typeMap != null) { + if (typeMap.isEmpty()) { + typeMap = new HashMap<>(4); + modulesByDate.put(moduleRevision, typeMap); + } typeMap.put(typedefName, returnType); } return returnType; -- 2.36.6