Hi

The point that I have in mind is this: Style files typically have many
different rules starting with e.g.
highway=*&  ...
The current iplementation in RuleSet.java and RuleIndex.java will first
create a set of all rules that might match for the existing tags of a given
element. Next, it processes each rule until the element is done.
Let's assume an element that has tag "highway" and maybe 4 other tags
If we have twenty rules with highway=* and none of them matches, we'll call
getTag("highway") twenty times, always with the same result. Although
getTag() is not very complex, it still means a lookup in a hash table.

I don't think that this happens in practice. All rules are rearranged
to have the most selective term first, so unless you have many rules
with highway=* by itself it is one
of the other terms in the expression that is used to select the rule.

So if you had 20 rules of the form:

highway=* & colour=red [0x7 ...]
highway=* & colour=green [0x7 ...]
...
highway=* & colour=blue [0x7 ...]

And you have an element with highway=primary,colour=blue then
the final rule is the only one that will checked, so you only call
getTag("highway") once.

There is a slight optimisation that could be done by moving common
tags back based on the tag name. See attached patch. This reduces the number of rules checked in two common cases in the test I ran.

..Steve
Index: src/uk/me/parabola/mkgmap/osmstyle/RuleFileReader.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/RuleFileReader.java	(revision 2161)
+++ src/uk/me/parabola/mkgmap/osmstyle/RuleFileReader.java	(revision )
@@ -280,11 +280,18 @@
 	 * in the expression than operations with higher values.
 	 */
 	private static int selectivity(Op op) {
+		String firstVal = op.getFirst().value();
 		switch (op.getType()) {
 		case EQUALS:
+			if ("amenity".equals(firstVal))
+				return 1;
+
 			return 0;
 		case EXISTS:
-			return 1;
+			if ("highway".equals(firstVal))
+				return 11;
+
+			return 10;
 
 		case AND:
 		case OR:
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to