From 56551e5f8027471688bc10670104b87b83128495 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 7 Nov 2014 20:03:32 +0100 Subject: [PATCH] Optimize xsql's use of collections Rather than performing class comparisons, we perform a simple instanceof check... and then rather than adding items one at a time, we use Collections.addAll(). Change-Id: I2e73788ab6f1625291970ad9b32d3b5d18ee8205 Signed-off-by: Robert Varga --- .../sal/dom/xsql/XSQLBluePrintRelation.java | 52 ++++++------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintRelation.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintRelation.java index 9053f00aae..55a35e041a 100644 --- a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintRelation.java +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintRelation.java @@ -81,59 +81,39 @@ public class XSQLBluePrintRelation implements Serializable { } public List execute(Object o) { - List result = new LinkedList<>(); if (o == null) { return null; } - if (Set.class.isAssignableFrom(o.getClass())) { - Set lst = (Set) o; - for (Object oo : lst) { + List result = new LinkedList<>(); + if (o instanceof Set) { + for (Object oo : (Set) o) { addToResult(result, execute(oo)); } - return result; - } else if (List.class.isAssignableFrom(o.getClass())) { - List lst = (List) o; - for (Object oo : lst) { + } else if (o instanceof List) { + for (Object oo : (List) o) { addToResult(result, execute(oo)); } - return result; - } else if (Map.class.isAssignableFrom(o.getClass())) { - Map map = (Map) o; - for (Object oo : map.values()) { + } else if (o instanceof Map) { + for (Object oo : ((Map) o).values()) { addToResult(result, execute(oo)); } - return result; + } else { + addToResult(result, XSQLCriteria.getValue(o, this.property)); } - - addToResult(result, XSQLCriteria.getValue(o, this.property)); - return result; } private static void addToResult(List result, Object o) { - if (o == null) { - return; - } - if (Set.class.isAssignableFrom(o.getClass())) { - Set lst = (Set) o; - for (Object oo : lst) { - result.add(oo); - } - } else if (List.class.isAssignableFrom(o.getClass())) { - List lst = (List) o; - for (Object oo : lst) { - result.add(oo); - } - } else if (Map.class.isAssignableFrom(o.getClass())) { - Map map = (Map) o; - for (Object oo : map.values()) { - result.add(oo); - } - } else { + if (o instanceof Set) { + result.addAll((Set)o); + } else if (o instanceof List) { + result.addAll((List)o); + } else if (o instanceof Map) { + result.addAll(((Map)o).values()); + } else if (o != null) { result.add(o); } } - } -- 2.36.6