From 050a0039573c63393678be3d9fff3f8fa780f36d Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 19 Oct 2011 17:48:35 +0200 Subject: [PATCH] Improve performance --- .../src/net/osmand/render/RenderingRule.java | 15 ++-- .../render/RenderingRuleSearchRequest.java | 68 ++++++++++--------- .../osmand/render/RenderingRulesStorage.java | 14 ++-- .../net/osmand/render/new_default.render.xml | 26 +++---- .../plus/render/MapRenderRepositories.java | 4 +- .../osmand/plus/render/OsmandRenderer.java | 32 +++++---- 6 files changed, 85 insertions(+), 74 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/render/RenderingRule.java b/DataExtractionOSM/src/net/osmand/render/RenderingRule.java index c2213b35dd..7d83b8bb9d 100644 --- a/DataExtractionOSM/src/net/osmand/render/RenderingRule.java +++ b/DataExtractionOSM/src/net/osmand/render/RenderingRule.java @@ -9,7 +9,7 @@ import java.util.Map.Entry; public class RenderingRule { - private List properties; + private RenderingRuleProperty[] properties; private int[] intProperties; private float[] floatProperties; private List ifElseChildren; @@ -19,12 +19,11 @@ public class RenderingRule { public RenderingRule(Map attributes, RenderingRulesStorage storage){ this.storage = storage; - this.properties = new ArrayList(); process(attributes); } private void process(Map attributes) { - properties = new ArrayList(attributes.size()); + ArrayList props = new ArrayList(attributes.size()); intProperties = new int[attributes.size()]; int i = 0; Iterator> it = attributes.entrySet().iterator(); @@ -32,7 +31,7 @@ public class RenderingRule { Entry e = it.next(); RenderingRuleProperty property = storage.PROPS.get(e.getKey()); if (property != null) { - properties.add(property); + props.add(property); if (property.isString()) { intProperties[i] = storage.getDictionaryValue(e.getValue()); @@ -47,13 +46,13 @@ public class RenderingRule { } i++; } - } + properties = props.toArray(new RenderingRuleProperty[props.size()]); } private int getPropertyIndex(String property){ - for (int i = 0; i < properties.size(); i++) { - RenderingRuleProperty prop = properties.get(i); + for (int i = 0; i < properties.length; i++) { + RenderingRuleProperty prop = properties[i]; if (prop.getAttrName().equals(property)) { return i; } @@ -102,7 +101,7 @@ public class RenderingRule { return floatProperties[ind]; } - public List getProperties() { + public RenderingRuleProperty[] getProperties() { return properties; } diff --git a/DataExtractionOSM/src/net/osmand/render/RenderingRuleSearchRequest.java b/DataExtractionOSM/src/net/osmand/render/RenderingRuleSearchRequest.java index b6eefe918a..888bfb8355 100644 --- a/DataExtractionOSM/src/net/osmand/render/RenderingRuleSearchRequest.java +++ b/DataExtractionOSM/src/net/osmand/render/RenderingRuleSearchRequest.java @@ -13,7 +13,7 @@ public class RenderingRuleSearchRequest { int[] savedValues; float[] savedFvalues; - private List searchedScope = new ArrayList(); + boolean searchResult = false; public final RenderingRuleStorageProperties ALL; @@ -67,82 +67,88 @@ public class RenderingRuleSearchRequest { } public boolean isFound() { - return searchedScope.size() > 0; + return searchResult; } public boolean search(int state) { + return search(state, true); + } + + public boolean search(int state, boolean loadOutput) { + searchResult = false; int tagKey = values[storage.PROPS.R_TAG.getId()]; int valueKey = values[storage.PROPS.R_VALUE.getId()]; - boolean result = search(state, tagKey, valueKey); + boolean result = searchInternal(state, tagKey, valueKey, loadOutput); if (result) { + searchResult = true; return true; } - result = search(state, tagKey, 0); + result = searchInternal(state, tagKey, 0, loadOutput); if (result) { + searchResult = true; return true; } - result = search(state, 0, 0); + result = searchInternal(state, 0, 0, loadOutput); if (result) { + searchResult = true; return true; } return false; } - private boolean search(int state, int tagKey, int valueKey) { - searchedScope.clear(); + + private boolean searchInternal(int state, int tagKey, int valueKey, boolean loadOutput) { values[storage.PROPS.R_TAG.getId()] = tagKey; values[storage.PROPS.R_VALUE.getId()] = valueKey; RenderingRule accept = storage.getRule(state, tagKey, valueKey); if (accept == null) { return false; } - boolean match = visitRule(accept); + boolean match = visitRule(accept, loadOutput); return match; } - private boolean visitRule(RenderingRule rule) { - boolean empty = true; - int ind = 0; - for(RenderingRuleProperty rp : rule.getProperties()){ - if(rp.isInputProperty()){ + private boolean visitRule(RenderingRule rule, boolean loadOutput) { + RenderingRuleProperty[] properties = rule.getProperties(); + for (int i = 0; i < properties.length; i++) { + RenderingRuleProperty rp = properties[i]; + if (rp.isInputProperty()) { boolean match; - if(rp.isFloat()){ - match = rp.accept(rule.getFloatProp(ind), fvalues[rp.getId()]); + if (rp.isFloat()) { + match = rp.accept(rule.getFloatProp(i), fvalues[rp.getId()]); } else { - match = rp.accept(rule.getIntProp(ind), values[rp.getId()]); + match = rp.accept(rule.getIntProp(i), values[rp.getId()]); } - if(!match){ + if (!match) { return false; } } - ind ++; + } + if (!loadOutput) { + return true; } // accept it - ind = 0; - for(RenderingRuleProperty rp : rule.getProperties()){ - if(rp.isOutputProperty()){ - empty = false; - if(rp.isFloat()){ - fvalues[rp.getId()] = rule.getFloatProp(ind); + for (int i = 0; i < properties.length; i++) { + RenderingRuleProperty rp = properties[i]; + if (rp.isOutputProperty()) { + searchResult = true; + if (rp.isFloat()) { + fvalues[rp.getId()] = rule.getFloatProp(i); } else { - values[rp.getId()] = rule.getIntProp(ind); + values[rp.getId()] = rule.getIntProp(i); } } - ind++; - } - if(!empty) { - searchedScope.add(rule); } for (RenderingRule rr : rule.getIfElseChildren()) { - boolean match = visitRule(rr); + boolean match = visitRule(rr, loadOutput); if (match) { break; } } for(RenderingRule rr : rule.getIfChildren()){ - visitRule(rr); + visitRule(rr, loadOutput); } return true; diff --git a/DataExtractionOSM/src/net/osmand/render/RenderingRulesStorage.java b/DataExtractionOSM/src/net/osmand/render/RenderingRulesStorage.java index 3a95af4434..2cc4edf14f 100644 --- a/DataExtractionOSM/src/net/osmand/render/RenderingRulesStorage.java +++ b/DataExtractionOSM/src/net/osmand/render/RenderingRulesStorage.java @@ -127,7 +127,7 @@ public class RenderingRulesStorage { RenderingRule toInsert = rr; RenderingRule previous = tagValueGlobalRules[state].get(key); if(previous != null){ - if(previous.getProperties().size() != 0){ + if(previous.getProperties().length != 0){ toInsert = new RenderingRule(Collections.EMPTY_MAP, RenderingRulesStorage.this); toInsert.addIfElseChildren(previous); } else { @@ -365,19 +365,19 @@ public class RenderingRulesStorage { public static void main(String[] args) throws SAXException, IOException { RenderingRulesStorage storage = new RenderingRulesStorage(); storage.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream("new_default.render.xml")); -// storage.printDebug(POLYGON_RULES, System.out); +// storage.printDebug(LINE_RULES, System.out); RenderingRuleSearchRequest searchRequest = new RenderingRuleSearchRequest(storage); - searchRequest.setStringFilter(storage.PROPS.R_TAG, "landuse"); - searchRequest.setStringFilter(storage.PROPS.R_VALUE, "grass"); + searchRequest.setStringFilter(storage.PROPS.R_TAG, "highway"); + searchRequest.setStringFilter(storage.PROPS.R_VALUE, "tertiary"); // searchRequest.setIntFilter(storage.PROPS.R_LAYER, 1); - searchRequest.setIntFilter(storage.PROPS.R_MINZOOM, 17); - searchRequest.setIntFilter(storage.PROPS.R_MAXZOOM, 17); + searchRequest.setIntFilter(storage.PROPS.R_MINZOOM, 14); + searchRequest.setIntFilter(storage.PROPS.R_MAXZOOM, 14); // searchRequest.setStringFilter(storage.PROPS.R_ORDER_TYPE, "line"); // searchRequest.setBooleanFilter(storage.PROPS.R_NIGHT_MODE, true); // searchRequest.setBooleanFilter(storage.PROPS.get("hmRendered"), true); - searchRequest.search(POLYGON_RULES); + searchRequest.search(LINE_RULES); printResult(searchRequest, System.out); } diff --git a/DataExtractionOSM/src/net/osmand/render/new_default.render.xml b/DataExtractionOSM/src/net/osmand/render/new_default.render.xml index 3e7dea1974..39d5a0f0d7 100644 --- a/DataExtractionOSM/src/net/osmand/render/new_default.render.xml +++ b/DataExtractionOSM/src/net/osmand/render/new_default.render.xml @@ -190,14 +190,14 @@ - - - - - - - - + + + + + + + + @@ -210,8 +210,8 @@ - - + + @@ -985,15 +985,15 @@ - - + + - + diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index a3b4c80d27..dd9e508f0d 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -258,11 +258,11 @@ public class MapRenderRepositories { TagValuePair pair = root.decodeType(type); if (pair != null) { renderingReq.setInitialTagValueZoom(pair.tag, pair.value, zoom); - if (renderingReq.search(mask)) { + if (renderingReq.search(mask, false)) { return true; } if (mask == RenderingRulesStorage.POINT_RULES) { - if (renderingReq.search(RenderingRulesStorage.TEXT_RULES)) { + if (renderingReq.search(RenderingRulesStorage.TEXT_RULES, false)) { return true; } diff --git a/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java b/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java index 56a46dd808..08f6662f79 100644 --- a/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java +++ b/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java @@ -816,19 +816,23 @@ public class OsmandRenderer { render.setIntFilter(render.ALL.R_TEXT_LENGTH, ref.length()); render.setBooleanFilter(render.ALL.R_REF, true); if(render.search(RenderingRulesStorage.TEXT_RULES)){ - TextDrawInfo text = new TextDrawInfo(ref); - text.fillProperties(render, xText, yText); - rc.textToDraw.add(text); + if(render.getIntPropertyValue(render.ALL.R_TEXT_SIZE) > 0){ + TextDrawInfo text = new TextDrawInfo(ref); + text.fillProperties(render, xText, yText); + rc.textToDraw.add(text); + } } } render.setInitialTagValueZoom(pair.tag, pair.value, rc.zoom); render.setIntFilter(render.ALL.R_TEXT_LENGTH, name.length()); - render.setBooleanFilter(render.ALL.R_REF, true); - if(render.search(RenderingRulesStorage.TEXT_RULES)){ - TextDrawInfo info = new TextDrawInfo(name); - info.fillProperties(render, xText, yText); - rc.textToDraw.add(info); + render.setBooleanFilter(render.ALL.R_REF, false); + if(render.search(RenderingRulesStorage.TEXT_RULES) ){ + if(render.getIntPropertyValue(render.ALL.R_TEXT_SIZE) > 0){ + TextDrawInfo info = new TextDrawInfo(name); + info.fillProperties(render, xText, yText); + rc.textToDraw.add(info); + } } } @@ -972,10 +976,12 @@ public class OsmandRenderer { render.setIntFilter(render.ALL.R_TEXT_LENGTH, ref.length()); render.setBooleanFilter(render.ALL.R_REF, true); if(render.search(RenderingRulesStorage.TEXT_RULES)){ - TextDrawInfo text = new TextDrawInfo(ref); - text.fillProperties(render, middlePoint.x, middlePoint.y); - text.pathRotate = pathRotate; - rc.textToDraw.add(text); + if(render.getIntPropertyValue(render.ALL.R_TEXT_SIZE) > 0){ + TextDrawInfo text = new TextDrawInfo(ref); + text.fillProperties(render, middlePoint.x, middlePoint.y); + text.pathRotate = pathRotate; + rc.textToDraw.add(text); + } } } @@ -984,7 +990,7 @@ public class OsmandRenderer { render.setInitialTagValueZoom(pair.tag, pair.value, rc.zoom); render.setIntFilter(render.ALL.R_TEXT_LENGTH, name.length()); render.setBooleanFilter(render.ALL.R_REF, false); - if (render.search(RenderingRulesStorage.TEXT_RULES)) { + if (render.search(RenderingRulesStorage.TEXT_RULES) && render.getIntPropertyValue(render.ALL.R_TEXT_SIZE) > 0) { TextDrawInfo text = new TextDrawInfo(name); if (render.getIntPropertyValue(render.ALL.R_TEXT_ON_PATH, 0) == 0) { text.fillProperties(render, middlePoint.x, middlePoint.y);