Improve performance

This commit is contained in:
Victor Shcherb 2011-10-19 17:48:35 +02:00
parent 292f84ffbf
commit 050a003957
6 changed files with 85 additions and 74 deletions

View file

@ -9,7 +9,7 @@ import java.util.Map.Entry;
public class RenderingRule { public class RenderingRule {
private List<RenderingRuleProperty> properties; private RenderingRuleProperty[] properties;
private int[] intProperties; private int[] intProperties;
private float[] floatProperties; private float[] floatProperties;
private List<RenderingRule> ifElseChildren; private List<RenderingRule> ifElseChildren;
@ -19,12 +19,11 @@ public class RenderingRule {
public RenderingRule(Map<String, String> attributes, RenderingRulesStorage storage){ public RenderingRule(Map<String, String> attributes, RenderingRulesStorage storage){
this.storage = storage; this.storage = storage;
this.properties = new ArrayList<RenderingRuleProperty>();
process(attributes); process(attributes);
} }
private void process(Map<String, String> attributes) { private void process(Map<String, String> attributes) {
properties = new ArrayList<RenderingRuleProperty>(attributes.size()); ArrayList<RenderingRuleProperty> props = new ArrayList<RenderingRuleProperty>(attributes.size());
intProperties = new int[attributes.size()]; intProperties = new int[attributes.size()];
int i = 0; int i = 0;
Iterator<Entry<String, String>> it = attributes.entrySet().iterator(); Iterator<Entry<String, String>> it = attributes.entrySet().iterator();
@ -32,7 +31,7 @@ public class RenderingRule {
Entry<String, String> e = it.next(); Entry<String, String> e = it.next();
RenderingRuleProperty property = storage.PROPS.get(e.getKey()); RenderingRuleProperty property = storage.PROPS.get(e.getKey());
if (property != null) { if (property != null) {
properties.add(property); props.add(property);
if (property.isString()) { if (property.isString()) {
intProperties[i] = storage.getDictionaryValue(e.getValue()); intProperties[i] = storage.getDictionaryValue(e.getValue());
@ -47,13 +46,13 @@ public class RenderingRule {
} }
i++; i++;
} }
} }
properties = props.toArray(new RenderingRuleProperty[props.size()]);
} }
private int getPropertyIndex(String property){ private int getPropertyIndex(String property){
for (int i = 0; i < properties.size(); i++) { for (int i = 0; i < properties.length; i++) {
RenderingRuleProperty prop = properties.get(i); RenderingRuleProperty prop = properties[i];
if (prop.getAttrName().equals(property)) { if (prop.getAttrName().equals(property)) {
return i; return i;
} }
@ -102,7 +101,7 @@ public class RenderingRule {
return floatProperties[ind]; return floatProperties[ind];
} }
public List<RenderingRuleProperty> getProperties() { public RenderingRuleProperty[] getProperties() {
return properties; return properties;
} }

View file

@ -13,7 +13,7 @@ public class RenderingRuleSearchRequest {
int[] savedValues; int[] savedValues;
float[] savedFvalues; float[] savedFvalues;
private List<RenderingRule> searchedScope = new ArrayList<RenderingRule>(); boolean searchResult = false;
public final RenderingRuleStorageProperties ALL; public final RenderingRuleStorageProperties ALL;
@ -67,82 +67,88 @@ public class RenderingRuleSearchRequest {
} }
public boolean isFound() { public boolean isFound() {
return searchedScope.size() > 0; return searchResult;
} }
public boolean search(int state) { 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 tagKey = values[storage.PROPS.R_TAG.getId()];
int valueKey = values[storage.PROPS.R_VALUE.getId()]; int valueKey = values[storage.PROPS.R_VALUE.getId()];
boolean result = search(state, tagKey, valueKey); boolean result = searchInternal(state, tagKey, valueKey, loadOutput);
if (result) { if (result) {
searchResult = true;
return true; return true;
} }
result = search(state, tagKey, 0); result = searchInternal(state, tagKey, 0, loadOutput);
if (result) { if (result) {
searchResult = true;
return true; return true;
} }
result = search(state, 0, 0); result = searchInternal(state, 0, 0, loadOutput);
if (result) { if (result) {
searchResult = true;
return true; return true;
} }
return false; 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_TAG.getId()] = tagKey;
values[storage.PROPS.R_VALUE.getId()] = valueKey; values[storage.PROPS.R_VALUE.getId()] = valueKey;
RenderingRule accept = storage.getRule(state, tagKey, valueKey); RenderingRule accept = storage.getRule(state, tagKey, valueKey);
if (accept == null) { if (accept == null) {
return false; return false;
} }
boolean match = visitRule(accept); boolean match = visitRule(accept, loadOutput);
return match; return match;
} }
private boolean visitRule(RenderingRule rule) { private boolean visitRule(RenderingRule rule, boolean loadOutput) {
boolean empty = true; RenderingRuleProperty[] properties = rule.getProperties();
int ind = 0; for (int i = 0; i < properties.length; i++) {
for(RenderingRuleProperty rp : rule.getProperties()){ RenderingRuleProperty rp = properties[i];
if(rp.isInputProperty()){ if (rp.isInputProperty()) {
boolean match; boolean match;
if(rp.isFloat()){ if (rp.isFloat()) {
match = rp.accept(rule.getFloatProp(ind), fvalues[rp.getId()]); match = rp.accept(rule.getFloatProp(i), fvalues[rp.getId()]);
} else { } 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; return false;
} }
} }
ind ++; }
if (!loadOutput) {
return true;
} }
// accept it // accept it
ind = 0; for (int i = 0; i < properties.length; i++) {
for(RenderingRuleProperty rp : rule.getProperties()){ RenderingRuleProperty rp = properties[i];
if(rp.isOutputProperty()){ if (rp.isOutputProperty()) {
empty = false; searchResult = true;
if(rp.isFloat()){ if (rp.isFloat()) {
fvalues[rp.getId()] = rule.getFloatProp(ind); fvalues[rp.getId()] = rule.getFloatProp(i);
} else { } else {
values[rp.getId()] = rule.getIntProp(ind); values[rp.getId()] = rule.getIntProp(i);
} }
} }
ind++;
}
if(!empty) {
searchedScope.add(rule);
} }
for (RenderingRule rr : rule.getIfElseChildren()) { for (RenderingRule rr : rule.getIfElseChildren()) {
boolean match = visitRule(rr); boolean match = visitRule(rr, loadOutput);
if (match) { if (match) {
break; break;
} }
} }
for(RenderingRule rr : rule.getIfChildren()){ for(RenderingRule rr : rule.getIfChildren()){
visitRule(rr); visitRule(rr, loadOutput);
} }
return true; return true;

View file

@ -127,7 +127,7 @@ public class RenderingRulesStorage {
RenderingRule toInsert = rr; RenderingRule toInsert = rr;
RenderingRule previous = tagValueGlobalRules[state].get(key); RenderingRule previous = tagValueGlobalRules[state].get(key);
if(previous != null){ if(previous != null){
if(previous.getProperties().size() != 0){ if(previous.getProperties().length != 0){
toInsert = new RenderingRule(Collections.EMPTY_MAP, RenderingRulesStorage.this); toInsert = new RenderingRule(Collections.EMPTY_MAP, RenderingRulesStorage.this);
toInsert.addIfElseChildren(previous); toInsert.addIfElseChildren(previous);
} else { } else {
@ -365,19 +365,19 @@ public class RenderingRulesStorage {
public static void main(String[] args) throws SAXException, IOException { public static void main(String[] args) throws SAXException, IOException {
RenderingRulesStorage storage = new RenderingRulesStorage(); RenderingRulesStorage storage = new RenderingRulesStorage();
storage.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream("new_default.render.xml")); 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); RenderingRuleSearchRequest searchRequest = new RenderingRuleSearchRequest(storage);
searchRequest.setStringFilter(storage.PROPS.R_TAG, "landuse"); searchRequest.setStringFilter(storage.PROPS.R_TAG, "highway");
searchRequest.setStringFilter(storage.PROPS.R_VALUE, "grass"); searchRequest.setStringFilter(storage.PROPS.R_VALUE, "tertiary");
// searchRequest.setIntFilter(storage.PROPS.R_LAYER, 1); // searchRequest.setIntFilter(storage.PROPS.R_LAYER, 1);
searchRequest.setIntFilter(storage.PROPS.R_MINZOOM, 17); searchRequest.setIntFilter(storage.PROPS.R_MINZOOM, 14);
searchRequest.setIntFilter(storage.PROPS.R_MAXZOOM, 17); searchRequest.setIntFilter(storage.PROPS.R_MAXZOOM, 14);
// searchRequest.setStringFilter(storage.PROPS.R_ORDER_TYPE, "line"); // searchRequest.setStringFilter(storage.PROPS.R_ORDER_TYPE, "line");
// searchRequest.setBooleanFilter(storage.PROPS.R_NIGHT_MODE, true); // searchRequest.setBooleanFilter(storage.PROPS.R_NIGHT_MODE, true);
// searchRequest.setBooleanFilter(storage.PROPS.get("hmRendered"), true); // searchRequest.setBooleanFilter(storage.PROPS.get("hmRendered"), true);
searchRequest.search(POLYGON_RULES); searchRequest.search(LINE_RULES);
printResult(searchRequest, System.out); printResult(searchRequest, System.out);
} }

View file

@ -190,14 +190,14 @@
<!-- Highway text --> <!-- Highway text -->
<group> <group>
<filter tag="highway" value="motorway" textOrder="6"/> <filter tag="highway" value="motorway" ref="false" textOrder="6"/>
<filter tag="highway" value="motorway_link" textOrder="7"/> <filter tag="highway" value="motorway_link" ref="false" textOrder="7"/>
<filter tag="highway" value="trunk" textOrder="6"/> <filter tag="highway" value="trunk" ref="false" textOrder="6"/>
<filter tag="highway" value="trunk_link" textOrder="7"/> <filter tag="highway" value="trunk_link" ref="false" textOrder="7"/>
<filter tag="highway" value="primary" textOrder="7"/> <filter tag="highway" value="primary" ref="false" textOrder="7"/>
<filter tag="highway" value="primary_link" textOrder="8"/> <filter tag="highway" value="primary_link" ref="false" textOrder="8"/>
<filter tag="highway" value="secondary" textOrder="8"/> <filter tag="highway" value="secondary" ref="false" textOrder="8"/>
<filter tag="highway" value="secondary_link" textOrder="9"/> <filter tag="highway" value="secondary_link" ref="false" textOrder="9"/>
<groupFilter textOnPath="true"> <groupFilter textOnPath="true">
<filter minzoom="13" maxzoom="13" textSize="12" /> <filter minzoom="13" maxzoom="13" textSize="12" />
@ -210,8 +210,8 @@
</group> </group>
<group> <group>
<filter tag="highway" value="tertiary" textOrder="8"/> <filter tag="highway" value="tertiary" ref="false" textOrder="8"/>
<filter tag="highway" value="tertiary_link" textOrder="9"/> <filter tag="highway" value="tertiary_link" ref="false" textOrder="9"/>
<filter tag="highway" value="road" textOrder="9"/> <filter tag="highway" value="road" textOrder="9"/>
<filter tag="highway" value="unclassified" textOrder="9"/> <filter tag="highway" value="unclassified" textOrder="9"/>
@ -985,15 +985,15 @@
</group> </group>
<group> <group>
<filter tag="highway" value="tertiary" maxzoom="13" /> <filter tag="highway" value="tertiary" />
<filter tag="highway" value="tertiary_link" maxzoom="13" /> <filter tag="highway" value="tertiary_link" />
<groupFilter color="#fefeb3" color_2="#fefeb3" shadowColor="#bababa"> <groupFilter color="#fefeb3" color_2="#fefeb3" shadowColor="#bababa">
<filter minzoom="10" maxzoom="10" strokeWidth="3" /> <filter minzoom="10" maxzoom="10" strokeWidth="3" />
<filter minzoom="11" maxzoom="11" strokeWidth="4" /> <filter minzoom="11" maxzoom="11" strokeWidth="4" />
<filter minzoom="12" maxzoom="12" strokeWidth="5" /> <filter minzoom="12" maxzoom="12" strokeWidth="5" />
<filter minzoom="13" maxzoom="13" strokeWidth="6" /> <filter minzoom="13" maxzoom="13" strokeWidth="6" />
<!-- bridge --> <!-- bridge -->
<filter layer="1" cap_2="SQUARE" color="#000000"> <filter layer="1" cap_2="SQUARE" color="#000000">
<filter minzoom="13" maxzoom="14" strokeWidth="8" strokeWidth_2="6" /> <filter minzoom="13" maxzoom="14" strokeWidth="8" strokeWidth_2="6" />
<filter minzoom="15" maxzoom="15" strokeWidth="10" strokeWidth_2="8" /> <filter minzoom="15" maxzoom="15" strokeWidth="10" strokeWidth_2="8" />
<filter minzoom="16" maxzoom="16" strokeWidth="12" strokeWidth_2="10" /> <filter minzoom="16" maxzoom="16" strokeWidth="12" strokeWidth_2="10" />

View file

@ -258,11 +258,11 @@ public class MapRenderRepositories {
TagValuePair pair = root.decodeType(type); TagValuePair pair = root.decodeType(type);
if (pair != null) { if (pair != null) {
renderingReq.setInitialTagValueZoom(pair.tag, pair.value, zoom); renderingReq.setInitialTagValueZoom(pair.tag, pair.value, zoom);
if (renderingReq.search(mask)) { if (renderingReq.search(mask, false)) {
return true; return true;
} }
if (mask == RenderingRulesStorage.POINT_RULES) { if (mask == RenderingRulesStorage.POINT_RULES) {
if (renderingReq.search(RenderingRulesStorage.TEXT_RULES)) { if (renderingReq.search(RenderingRulesStorage.TEXT_RULES, false)) {
return true; return true;
} }

View file

@ -816,19 +816,23 @@ public class OsmandRenderer {
render.setIntFilter(render.ALL.R_TEXT_LENGTH, ref.length()); render.setIntFilter(render.ALL.R_TEXT_LENGTH, ref.length());
render.setBooleanFilter(render.ALL.R_REF, true); render.setBooleanFilter(render.ALL.R_REF, true);
if(render.search(RenderingRulesStorage.TEXT_RULES)){ if(render.search(RenderingRulesStorage.TEXT_RULES)){
TextDrawInfo text = new TextDrawInfo(ref); if(render.getIntPropertyValue(render.ALL.R_TEXT_SIZE) > 0){
text.fillProperties(render, xText, yText); TextDrawInfo text = new TextDrawInfo(ref);
rc.textToDraw.add(text); text.fillProperties(render, xText, yText);
rc.textToDraw.add(text);
}
} }
} }
render.setInitialTagValueZoom(pair.tag, pair.value, rc.zoom); render.setInitialTagValueZoom(pair.tag, pair.value, rc.zoom);
render.setIntFilter(render.ALL.R_TEXT_LENGTH, name.length()); render.setIntFilter(render.ALL.R_TEXT_LENGTH, name.length());
render.setBooleanFilter(render.ALL.R_REF, true); render.setBooleanFilter(render.ALL.R_REF, false);
if(render.search(RenderingRulesStorage.TEXT_RULES)){ if(render.search(RenderingRulesStorage.TEXT_RULES) ){
TextDrawInfo info = new TextDrawInfo(name); if(render.getIntPropertyValue(render.ALL.R_TEXT_SIZE) > 0){
info.fillProperties(render, xText, yText); TextDrawInfo info = new TextDrawInfo(name);
rc.textToDraw.add(info); 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.setIntFilter(render.ALL.R_TEXT_LENGTH, ref.length());
render.setBooleanFilter(render.ALL.R_REF, true); render.setBooleanFilter(render.ALL.R_REF, true);
if(render.search(RenderingRulesStorage.TEXT_RULES)){ if(render.search(RenderingRulesStorage.TEXT_RULES)){
TextDrawInfo text = new TextDrawInfo(ref); if(render.getIntPropertyValue(render.ALL.R_TEXT_SIZE) > 0){
text.fillProperties(render, middlePoint.x, middlePoint.y); TextDrawInfo text = new TextDrawInfo(ref);
text.pathRotate = pathRotate; text.fillProperties(render, middlePoint.x, middlePoint.y);
rc.textToDraw.add(text); text.pathRotate = pathRotate;
rc.textToDraw.add(text);
}
} }
} }
@ -984,7 +990,7 @@ public class OsmandRenderer {
render.setInitialTagValueZoom(pair.tag, pair.value, rc.zoom); render.setInitialTagValueZoom(pair.tag, pair.value, rc.zoom);
render.setIntFilter(render.ALL.R_TEXT_LENGTH, name.length()); render.setIntFilter(render.ALL.R_TEXT_LENGTH, name.length());
render.setBooleanFilter(render.ALL.R_REF, false); 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); TextDrawInfo text = new TextDrawInfo(name);
if (render.getIntPropertyValue(render.ALL.R_TEXT_ON_PATH, 0) == 0) { if (render.getIntPropertyValue(render.ALL.R_TEXT_ON_PATH, 0) == 0) {
text.fillProperties(render, middlePoint.x, middlePoint.y); text.fillProperties(render, middlePoint.x, middlePoint.y);