From d62522982f39f2610f0d9d26d9908ccb1ea24222 Mon Sep 17 00:00:00 2001 From: Sang Gi Ryu Date: Thu, 23 Oct 2014 13:27:50 +0900 Subject: [PATCH] Performance improvement Use entrySet instead of keySet followed by a lookup per key as the former is more efficient. Issue: SPR-12363 --- .../src/main/java/org/springframework/ui/ModelMap.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/ui/ModelMap.java b/spring-context/src/main/java/org/springframework/ui/ModelMap.java index 755fe59811..5db8b7fb7b 100644 --- a/spring-context/src/main/java/org/springframework/ui/ModelMap.java +++ b/spring-context/src/main/java/org/springframework/ui/ModelMap.java @@ -127,9 +127,10 @@ public class ModelMap extends LinkedHashMap { */ public ModelMap mergeAttributes(Map attributes) { if (attributes != null) { - for (String key : attributes.keySet()) { + for (Map.Entry entry : attributes.entrySet()) { + String key = entry.getKey(); if (!containsKey(key)) { - put(key, attributes.get(key)); + put(key, entry.getValue()); } } }