#11834 closed enhancement (fixed)
[Patch] Use visitor pattern for key/value lookup.
Reported by: | michael2402 | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | 15.09 |
Component: | Core mappaint | Version: | |
Keywords: | Cc: |
Description
Currently, MapCSS creates a HashMap to get the keys from each primitive.
We can speed this up a lot using a visitor pattern.
Attachments (1)
Change History (7)
by , 10 years ago
Attachment: | 0001-Made-MapCSS-use-the-visitor-pattern-to-retrive-tags-.patch added |
---|
comment:1 by , 10 years ago
Milestone: | → 15.09 |
---|
comment:3 by , 10 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
While attempting to use this visitor for the UntaggedNode
test, I needed also to obtain the current primitive. The following modification also provides the primitive to the visitor (which can be ignored when not needed). What do you think?
-
src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
diff --git a/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java b/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java index 490764f..991df5e 100644
a b public abstract class AbstractPrimitive implements IPrimitive { 37 37 /** 38 38 * This method gets called for every tag received. 39 39 * 40 * @param primitive This primitive 40 41 * @param key The key 41 42 * @param value The value 42 43 */ 43 void visitKeyValue( String key, String value);44 void visitKeyValue(AbstractPrimitive primitive, String key, String value); 44 45 } 45 46 46 47 private static final AtomicLong idCounter = new AtomicLong(0); … … public abstract class AbstractPrimitive implements IPrimitive { 519 520 final String[] keys = this.keys; 520 521 if (keys != null) { 521 522 for (int i = 0; i < keys.length; i += 2) { 522 visitor.visitKeyValue( keys[i], keys[i + 1]);523 visitor.visitKeyValue(this, keys[i], keys[i + 1]); 523 524 } 524 525 } 525 526 }
comment:4 by , 10 years ago
This is a good improvement. The overhead should be minimal (since we are only passing one more parameter).
Don't you rather want to use a visitor for each node in that test? You could let it collect all information for the node and then display the result. Performance should not be that critical there.
Looks good to me. Seems to be a safer alternative to #11653.