Index: trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java	(revision 7062)
+++ trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java	(revision 7064)
@@ -123,5 +123,5 @@
             final TagCheck check = new TagCheck(rule);
             boolean containsSetClassExpression = false;
-            for (Instruction i : rule.declaration) {
+            for (Instruction i : rule.declaration.instructions) {
                 if (i instanceof Instruction.AssignmentInstruction) {
                     final Instruction.AssignmentInstruction ai = (Instruction.AssignmentInstruction) i;
@@ -161,7 +161,7 @@
             }
             if (check.errors.isEmpty() && !containsSetClassExpression) {
-                throw new RuntimeException("No throwError/throwWarning/throwOther given! You should specify a validation error message for " + rule.selectors);
+                throw new RuntimeException("No throwError/throwWarning/throwOther given! You should specify a validation error message for " + rule.selector);
             } else if (check.errors.size() > 1) {
-                throw new RuntimeException("More than one throwError/throwWarning/throwOther given! You should specify a single validation error message for " + rule.selectors);
+                throw new RuntimeException("More than one throwError/throwWarning/throwOther given! You should specify a single validation error message for " + rule.selector);
             }
             return check;
@@ -191,11 +191,8 @@
             for (Iterator<MapCSSRule> it = source.rules.iterator(); it.hasNext(); ) {
                 MapCSSRule x = it.next();
-                if (x.selectors.size() == 1) {
-                    Selector sel = x.selectors.get(0);
-                    if (sel instanceof GeneralSelector) {
-                        GeneralSelector gs = (GeneralSelector) sel;
-                        if ("meta".equals(gs.base) && gs.getConditions().isEmpty()) {
-                            it.remove();
-                        }
+                if (x.selector instanceof GeneralSelector) {
+                    GeneralSelector gs = (GeneralSelector) x.selector;
+                    if ("meta".equals(gs.base) && gs.getConditions().isEmpty()) {
+                        it.remove();
                     }
                 }
@@ -214,9 +211,7 @@
 
         Selector whichSelectorMatchesEnvironment(Environment env) {
-            for (Selector i : rule.selectors) {
-                env.clearSelectorMatchingInformation();
-                if (i.matches(env)) {
-                    return i;
-                }
+            env.clearSelectorMatchingInformation();
+            if (rule.selector.matches(env)) {
+                return rule.selector;
             }
             return null;
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj	(revision 7062)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj	(revision 7064)
@@ -18,4 +18,5 @@
 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
+import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule.Declaration;
 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
@@ -48,4 +49,5 @@
     MapCSSStyleSource sheet;
     StringBuilder sb;
+    int declarationCounter;
 
     /**
@@ -71,4 +73,5 @@
     public MapCSSParser(InputStream in, String encoding, LexicalState initState) {
         this(createTokenManager(in, encoding, initState));
+        declarationCounter = 0;
     }
 
@@ -469,5 +472,4 @@
 void sheet(MapCSSStyleSource sheet):
 {
-    MapCSSRule r;
 }
 {
@@ -476,5 +478,5 @@
     (
         try {
-            r=rule() { if (r != null) { sheet.rules.add(r); } } w()
+            rule() w()
         } catch (MapCSSException mex) {
             error_skipto(RBRACE, mex);
@@ -488,9 +490,9 @@
 }
 
-MapCSSRule rule():
+void rule():
 {
     List<Selector> selectors = new ArrayList<Selector>();
     Selector sel;
-    List<Instruction> decl;
+    Declaration decl;
 }
 {
@@ -501,5 +503,9 @@
     )*
     decl=declaration()
-    { return new MapCSSRule(selectors, decl); }
+    { 
+        for (Selector s : selectors) {
+            sheet.rules.add(new MapCSSRule(s, decl));
+        }
+    }
 }
 
@@ -707,5 +713,5 @@
 }
 
-List<Instruction> declaration() :
+Declaration declaration() :
 {
     List<Instruction> ins = new ArrayList<Instruction>();
@@ -723,5 +729,5 @@
             ( <EQUAL> val=expression() )?
             { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val, true)); }
-            ( <RBRACE> { return ins; } | <SEMICOLON> w() )
+            ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> w() )
         )
     |
@@ -732,10 +738,10 @@
                 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
                 w()
-                ( <RBRACE> { return ins; } | <SEMICOLON> w() )
+                ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> w() )
             |
             LOOKAHEAD( expression() ( <SEMICOLON> | <RBRACE> ) )
                 val=expression()
                 { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
-                ( <RBRACE> { return ins; } | <SEMICOLON> w() )
+                ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> w() )
             |
                 val=readRaw() w() { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
@@ -743,5 +749,5 @@
     )*
     <RBRACE>
-    { return ins; }
+    { return new Declaration(ins, declarationCounter++); }
 }
 
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSRule.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSRule.java	(revision 7062)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSRule.java	(revision 7064)
@@ -9,9 +9,20 @@
 public class MapCSSRule {
 
-    public List<Selector> selectors;
-    public List<Instruction> declaration;
+    public final Selector selector;
+    public final Declaration declaration;
 
-    public MapCSSRule(List<Selector> selectors, List<Instruction> declaration) {
-        this.selectors = selectors;
+    public static class Declaration {
+        public final List<Instruction> instructions;
+        // declarations in the StyleSource are numbered consecutively
+        public final int idx;
+
+        public Declaration(List<Instruction> instructions, int idx) {
+            this.instructions = instructions;
+            this.idx = idx;
+        }
+    }
+    
+    public MapCSSRule(Selector selector, Declaration declaration) {
+        this.selector = selector;
         this.declaration = declaration;
     }
@@ -23,5 +34,5 @@
      */
     public void execute(Environment env) {
-        for (Instruction i : declaration) {
+        for (Instruction i : declaration.instructions) {
             i.execute(env);
         }
@@ -30,5 +41,5 @@
     @Override
     public String toString() {
-        return Utils.join(",", selectors) + " {\n  " + Utils.join("\n  ", declaration) + "\n}";
+        return selector + " {\n  " + Utils.join("\n  ", declaration.instructions) + "\n}";
     }
 }
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java	(revision 7062)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java	(revision 7064)
@@ -28,5 +28,4 @@
 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector;
 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
-import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.OptimizedGeneralSelector;
 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser;
 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
@@ -118,44 +117,33 @@
         // optimization: filter rules for different primitive types
         for (MapCSSRule r: rules) {
-            List<Selector> nodeSel = new ArrayList<>();
-            List<Selector> waySel = new ArrayList<>();
-            List<Selector> relationSel = new ArrayList<>();
-            List<Selector> multipolygonSel = new ArrayList<>();
-            for (Selector sel : r.selectors) {
-                // find the rightmost selector, this must be a GeneralSelector
-                Selector selRightmost = sel;
-                while (selRightmost instanceof ChildOrParentSelector) {
-                    selRightmost = ((ChildOrParentSelector) selRightmost).right;
-                }
-                Selector optimizedSel = sel.optimizedBaseCheck();
-                switch (((GeneralSelector) selRightmost).getBase()) {
-                    case "node":
-                        nodeSel.add(optimizedSel);
-                        break;
-                    case "way":
-                        waySel.add(optimizedSel);
-                        break;
-                    case "area":
-                        waySel.add(optimizedSel);
-                        multipolygonSel.add(optimizedSel);
-                        break;
-                    case "relation":
-                        relationSel.add(optimizedSel);
-                        multipolygonSel.add(optimizedSel);
-                        break;
-                    case "*":
-                        nodeSel.add(optimizedSel);
-                        waySel.add(optimizedSel);
-                        relationSel.add(optimizedSel);
-                        multipolygonSel.add(optimizedSel);
-                        break;
-                }
-            }
-            nodeRules.add(new MapCSSRule(nodeSel, r.declaration));
-            wayRules.add(new MapCSSRule(waySel, r.declaration));
-            relationRules.add(new MapCSSRule(relationSel, r.declaration));
-            multipolygonRules.add(new MapCSSRule(multipolygonSel, r.declaration));
-        }
-        rules.clear();
+            // find the rightmost selector, this must be a GeneralSelector
+            Selector selRightmost = r.selector;
+            while (selRightmost instanceof ChildOrParentSelector) {
+                selRightmost = ((ChildOrParentSelector) selRightmost).right;
+            }
+            MapCSSRule optRule = new MapCSSRule(r.selector.optimizedBaseCheck(), r.declaration);
+            switch (((GeneralSelector) selRightmost).getBase()) {
+                case "node":
+                    nodeRules.add(optRule);
+                    break;
+                case "way":
+                    wayRules.add(optRule);
+                    break;
+                case "area":
+                    wayRules.add(optRule);
+                    multipolygonRules.add(optRule);
+                    break;
+                case "relation":
+                    relationRules.add(optRule);
+                    multipolygonRules.add(optRule);
+                    break;
+                case "*":
+                    nodeRules.add(optRule);
+                    wayRules.add(optRule);
+                    relationRules.add(optRule);
+                    multipolygonRules.add(optRule);
+                    break;
+            }
+        }
     }
     
@@ -217,15 +205,12 @@
         Environment env = new Environment(n, mc, "default", this);
 
-        NEXT_RULE:
         for (MapCSSRule r : rules) {
-            for (Selector s : r.selectors) {
-                if ((s instanceof GeneralSelector)) {
-                    GeneralSelector gs = (GeneralSelector) s;
-                    if (gs.getBase().equals(type)) {
-                        if (!gs.matchesConditions(env)) {
-                            continue NEXT_RULE;
-                        }
-                        r.execute(env);
+            if ((r.selector instanceof GeneralSelector)) {
+                GeneralSelector gs = (GeneralSelector) r.selector;
+                if (gs.getBase().equals(type)) {
+                    if (!gs.matchesConditions(env)) {
+                        continue;
                     }
+                    r.execute(env);
                 }
             }
@@ -254,32 +239,37 @@
             }
         }
-        RULE: for (MapCSSRule r : matchingRules) {
-            for (Selector s : r.selectors) {
-                env.clearSelectorMatchingInformation();
-                if (s.matches(env)) { // as side effect env.parent will be set (if s is a child selector)
-                    if (s.getRange().contains(scale)) {
-                        mc.range = Range.cut(mc.range, s.getRange());
-                    } else {
-                        mc.range = mc.range.reduceAround(scale, s.getRange());
-                        continue;
+        
+        // the declaration indices are sorted, so it suffices to save the
+        // last used index
+        int lastDeclUsed = -1;
+        
+        for (MapCSSRule r : matchingRules) {
+            env.clearSelectorMatchingInformation();
+            if (r.selector.matches(env)) { // as side effect env.parent will be set (if s is a child selector)
+                Selector s = r.selector;
+                if (s.getRange().contains(scale)) {
+                    mc.range = Range.cut(mc.range, s.getRange());
+                } else {
+                    mc.range = mc.range.reduceAround(scale, s.getRange());
+                    continue;
+                }
+
+                if (r.declaration.idx == lastDeclUsed) continue; // don't apply one declaration more than once
+                lastDeclUsed = r.declaration.idx;
+                String sub = s.getSubpart();
+                if (sub == null) {
+                    sub = "default";
+                }
+                else if ("*".equals(sub)) {
+                    for (Entry<String, Cascade> entry : mc.getLayers()) {
+                        env.layer = entry.getKey();
+                        if (Utils.equal(env.layer, "*")) {
+                            continue;
+                        }
+                        r.execute(env);
                     }
-
-                    String sub = s.getSubpart();
-                    if (sub == null) {
-                        sub = "default";
-                    }
-                    else if ("*".equals(sub)) {
-                        for (Entry<String, Cascade> entry : mc.getLayers()) {
-                            env.layer = entry.getKey();
-                            if (Utils.equal(env.layer, "*")) {
-                                continue;
-                            }
-                            r.execute(env);
-                        }
-                    }
-                    env.layer = sub;
-                    r.execute(env);
-                    continue RULE;
-                }
+                }
+                env.layer = sub;
+                r.execute(env);
             }
         }
