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 {
private List<RenderingRuleProperty> properties;
private RenderingRuleProperty[] properties;
private int[] intProperties;
private float[] floatProperties;
private List<RenderingRule> ifElseChildren;
@ -19,12 +19,11 @@ public class RenderingRule {
public RenderingRule(Map<String, String> attributes, RenderingRulesStorage storage){
this.storage = storage;
this.properties = new ArrayList<RenderingRuleProperty>();
process(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()];
int i = 0;
Iterator<Entry<String, String>> it = attributes.entrySet().iterator();
@ -32,7 +31,7 @@ public class RenderingRule {
Entry<String, String> 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<RenderingRuleProperty> getProperties() {
public RenderingRuleProperty[] getProperties() {
return properties;
}

View file

@ -13,7 +13,7 @@ public class RenderingRuleSearchRequest {
int[] savedValues;
float[] savedFvalues;
private List<RenderingRule> searchedScope = new ArrayList<RenderingRule>();
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;

View file

@ -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);
}

View file

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

View file

@ -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;
}

View file

@ -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);