aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/cgBase.java
diff options
context:
space:
mode:
authorMichiel Korthuis <michiel.korthuis@topicus.nl>2011-08-17 11:33:36 +0200
committerMichiel Korthuis <michiel.korthuis@topicus.nl>2011-08-17 11:33:36 +0200
commit3dcfb136737cd5c50ae5369162db4257a9dbc103 (patch)
tree52f95a4e3602a7520e50b0ee504bb2c7728bfae9 /src/cgeo/geocaching/cgBase.java
parent8fc7746eaa67f04aa4168e84627b4cb0be860895 (diff)
downloadcgeo-3dcfb136737cd5c50ae5369162db4257a9dbc103.zip
cgeo-3dcfb136737cd5c50ae5369162db4257a9dbc103.tar.gz
cgeo-3dcfb136737cd5c50ae5369162db4257a9dbc103.tar.bz2
Performance improvement - when iterating over map, use entryset iterator to avoid unnecessary Map.get(key) lookup
Diffstat (limited to 'src/cgeo/geocaching/cgBase.java')
-rw-r--r--src/cgeo/geocaching/cgBase.java73
1 files changed, 36 insertions, 37 deletions
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java
index 8f69eab..665623a 100644
--- a/src/cgeo/geocaching/cgBase.java
+++ b/src/cgeo/geocaching/cgBase.java
@@ -28,8 +28,8 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-import java.util.Set;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
@@ -4220,14 +4220,13 @@ public class cgBase {
}
if (params != null) {
- Object[] keys = params.keySet().toArray();
+ Set<Map.Entry<String, String>> entrySet = params.entrySet();
ArrayList<String> paramsEncoded = new ArrayList<String>();
- String key;
- String value;
-
- for (int i = 0; i < keys.length; i++) {
- key = (String) keys[i];
- value = (String) params.get(key);
+
+ for(Map.Entry<String, String> entry : entrySet)
+ {
+ String key = entry.getKey();
+ String value = entry.getValue();
if (key.charAt(0) == '^') {
key = "";
@@ -4314,25 +4313,25 @@ public class cgBase {
}
final Map<String, ?> prefsAll = prefs.getAll();
- final Set<String> prefsKeys = prefsAll.keySet();
-
- for (String key : prefsKeys) {
+ final Set<? extends Map.Entry<String, ?>> entrySet = prefsAll.entrySet();
+
+ for(Map.Entry<String, ?> entry : entrySet){
+ String key = entry.getKey();
if (key.matches("cookie_.+")) {
final String cookieKey = key.substring(7);
- final String cookieValue = (String) prefsAll.get(key);
+ final String cookieValue = (String) entry.getValue();
cookies.put(cookieKey, cookieValue);
}
}
}
- if (cookies != null && !cookies.isEmpty() && cookies.keySet().size() > 0) {
- final Object[] keys = cookies.keySet().toArray();
+ if (cookies != null) {
+ final Set<Map.Entry<String, String>> entrySet = cookies.entrySet();
final ArrayList<String> cookiesEncoded = new ArrayList<String>();
-
- for (int i = 0; i < keys.length; i++) {
- String value = cookies.get(keys[i].toString());
- cookiesEncoded.add(keys[i] + "=" + value);
+
+ for(Map.Entry<String, String> entry : entrySet){
+ cookiesEncoded.add(entry.getKey() + "=" + entry.getValue());
}
if (cookiesEncoded.size() > 0) {
@@ -4344,13 +4343,13 @@ public class cgBase {
Map<String, ?> prefsValues = prefs.getAll();
if (prefsValues != null && prefsValues.size() > 0 && prefsValues.keySet().size() > 0) {
- final Object[] keys = prefsValues.keySet().toArray();
+ final Set<? extends Map.Entry<String, ?>> entrySet = prefsValues.entrySet();
final ArrayList<String> cookiesEncoded = new ArrayList<String>();
- final int length = keys.length;
- for (int i = 0; i < length; i++) {
- if (keys[i].toString().length() > 7 && keys[i].toString().substring(0, 7).equals("cookie_")) {
- cookiesEncoded.add(keys[i].toString().substring(7) + "=" + prefsValues.get(keys[i].toString()));
+ for(Map.Entry<String, ?> entry : entrySet){
+ String key = entry.getKey();
+ if (key.length() > 7 && key.substring(0, 7).equals("cookie_")) {
+ cookiesEncoded.add(key + "=" + entry.getValue());
}
}
@@ -4576,12 +4575,13 @@ public class cgBase {
}
final Map<String, ?> prefsAll = prefs.getAll();
- final Set<String> prefsKeys = prefsAll.keySet();
-
- for (String key : prefsKeys) {
+ final Set<? extends Map.Entry<String, ?>> entrySet = prefsAll.entrySet();
+
+ for(Map.Entry<String, ?> entry : entrySet){
+ String key = entry.getKey();
if (key.matches("cookie_.+")) {
final String cookieKey = key.substring(7);
- final String cookieValue = (String) prefsAll.get(key);
+ final String cookieValue = (String) entry.getValue();
cookies.put(cookieKey, cookieValue);
}
@@ -4589,12 +4589,11 @@ public class cgBase {
}
if (cookies != null) {
- final Object[] keys = cookies.keySet().toArray();
+ final Set<Map.Entry<String, String>> entrySet = cookies.entrySet();
final ArrayList<String> cookiesEncoded = new ArrayList<String>();
-
- for (int i = 0; i < keys.length; i++) {
- String value = cookies.get(keys[i].toString());
- cookiesEncoded.add(keys[i] + "=" + value);
+
+ for(Map.Entry<String, String> entry : entrySet){
+ cookiesEncoded.add(entry.getKey() + "=" + entry.getValue());
}
if (cookiesEncoded.size() > 0) {
@@ -4606,13 +4605,13 @@ public class cgBase {
Map<String, ?> prefsValues = prefs.getAll();
if (prefsValues != null && prefsValues.size() > 0) {
- final Object[] keys = prefsValues.keySet().toArray();
+ final Set<? extends Map.Entry<String, ?>> entrySet = prefsValues.entrySet();
final ArrayList<String> cookiesEncoded = new ArrayList<String>();
- final int length = keys.length;
- for (int i = 0; i < length; i++) {
- if (keys[i].toString().length() > 7 && keys[i].toString().substring(0, 7).equals("cookie_")) {
- cookiesEncoded.add(keys[i].toString().substring(7) + "=" + prefsValues.get(keys[i].toString()));
+ for(Map.Entry<String, ?> entry : entrySet){
+ String key = entry.getKey();
+ if (key.length() > 7 && key.substring(0, 7).equals("cookie_")) {
+ cookiesEncoded.add(key + "=" + entry.getValue());
}
}