Stephen McKamey avatar Stephen McKamey committed e8a4fdb

using HashSet instead of HashMap

Comments (0)

Files changed (2)

duel-compiler/src/main/java/org/duelengine/duel/ast/ElementNode.java

 	private static final String CMD_LOAD = "$load";
 
 	private static final String CONFIG_RESOURCE = "org.duelengine.duel.ast.HTMLTags";
-	private static final Map<String, Boolean> voidTags;
-	private static final Map<String, Boolean> linkTags;
-	private static final Map<String, Boolean> linkAttrs;
-	private static final Map<String, Boolean> boolAttrs;
+	private static final Set<String> voidTags;
+	private static final Set<String> linkTags;
+	private static final Set<String> linkAttrs;
+	private static final Set<String> boolAttrs;
 
 	private final String tagName;
 	private final boolean isVoid;
 		String[] items = (config != null) && config.containsKey("voidTags") ?
 			config.getString("voidTags").split("\\s+") : new String[0];
 
-		Map<String, Boolean> map = new HashMap<String, Boolean>(items.length);
+		Set<String> set = new HashSet<String>(items.length);
 		for (String value : items) {
-			map.put(value, true);
+			set.add(value);
 		}
 
-		voidTags = map;
+		voidTags = set;
 
 		items = (config != null) && config.containsKey("linkTags") ?
 			config.getString("linkTags").split("\\s+") : new String[0];
 
-		map = new HashMap<String, Boolean>(items.length);
+		set = new HashSet<String>(items.length);
 		for (String value : items) {
-			map.put(value, true);
+			set.add(value);
 		}
 
-		linkTags = map;
+		linkTags = set;
 
 		items = (config != null) && config.containsKey("linkAttrs") ?
 			config.getString("linkAttrs").split("\\s+") : new String[0];
 
-		map = new HashMap<String, Boolean>(items.length);
+		set = new HashSet<String>(items.length);
 		for (String value : items) {
-			map.put(value, true);
+			set.add(value);
 		}
 
-		linkAttrs = map;
+		linkAttrs = set;
 
 		items = (config != null) && config.containsKey("boolAttrs") ?
 			config.getString("boolAttrs").split("\\s+") : new String[0];
 
-		map = new HashMap<String, Boolean>(items.length);
+		set = new HashSet<String>(items.length);
 		for (String value : items) {
-			map.put(value, true);
+			set.add(value);
 		}
 
-		boolAttrs = map;
+		boolAttrs = set;
 	}
 
 	public ElementNode(String name, int index, int line, int column) {
 		super(index, line, column);
 
 		this.tagName = name;
-		this.isVoid = (name == null) || voidTags.containsKey(name);
-		this.isLinkableTag = (name != null) && linkTags.containsKey(name);
+		this.isVoid = (name == null) || voidTags.contains(name);
+		this.isLinkableTag = (name != null) && linkTags.contains(name);
 	}
 
 	public ElementNode(String name) {
 		this.tagName = name;
-		this.isVoid = (name == null) || voidTags.containsKey(name);
-		this.isLinkableTag = (name != null) && linkTags.containsKey(name);
+		this.isVoid = (name == null) || voidTags.contains(name);
+		this.isLinkableTag = (name != null) && linkTags.contains(name);
 	}
 
 	public ElementNode(String name, AttributePair[] attr, DuelNode... children) {
 		super(children);
 
 		this.tagName = name;
-		this.isVoid = (name == null) || voidTags.containsKey(name);
-		this.isLinkableTag = (name != null) && linkTags.containsKey(name);
+		this.isVoid = (name == null) || voidTags.contains(name);
+		this.isLinkableTag = (name != null) && linkTags.contains(name);
 
 		if (attr != null) {
 			for (AttributePair a : attr) {
 	}
 
 	public boolean isLinkAttribute(String name) {
-		return this.isLinkableTag && linkAttrs.containsKey(name);
+		return this.isLinkableTag && linkAttrs.contains(name);
 	}
 
 	public boolean isBoolAttribute(String name) {
-		return boolAttrs.containsKey(name);
+		return boolAttrs.contains(name);
 	}
 
 	public boolean hasAttributes() {

duel-runtime/src/main/java/org/duelengine/duel/JSUtility.java

 public final class JSUtility {
 
 	private static final String CONFIG_RESOURCE = "org.duelengine.duel.JSUtility";
-	private static Map<String, Boolean> reserved;
-	private static Map<String, Boolean> globals;
-	private static Map<String, Boolean> properties;
-	private static Map<String, Boolean> browser;
+	private static Set<String> reserved;
+	private static Set<String> globals;
+	private static Set<String> properties;
+	private static Set<String> browser;
 	private static boolean inited;
 
 	// static class
 				{
 					return false;
 				}
-				if (i == 0 && globals.containsKey(parts[i])) {
+				if (i == 0 && globals.contains(parts[i])) {
 					return false;
 				}
 			}
 			return true;
 		}
 
-		if (reserved.containsKey(ident)) {
+		if (reserved.contains(ident)) {
 			return false;
 		}
 
 			initLookups();
 		}
 
-		return globals.containsKey(ident) || browser.containsKey(ident);
+		return globals.contains(ident) || browser.contains(ident);
 	}
 
 	public static boolean isObjectProperty(String ident) {
 			initLookups();
 		}
 
-		return properties.containsKey(ident);
+		return properties.contains(ident);
 	}
 	
 	private static void initLookups() {
 
 		String[] tags;
-		Map<String, Boolean> map;
+		Set<String> set;
 
 		// definitions maintained in JSVocab.properties
 		ResourceBundle config = ResourceBundle.getBundle(CONFIG_RESOURCE, Locale.ROOT);
 		// reserved words
 		tags = (config != null) && config.containsKey("reserved") ?
 				config.getString("reserved").split(",") : new String[0];
-		map = new HashMap<String, Boolean>(tags.length);
+		set = new HashSet<String>(tags.length);
 		for (String value : tags) {
-			map.put(value, true);
+			set.add(value);
 		}
 
 		// add Object properties to reserved words
 		tags = (config != null) && config.containsKey("properties") ?
 				config.getString("properties").split(",") : new String[0];
 		for (String value : tags) {
-			map.put(value, true);
+			set.add(value);
 		}
-		reserved = map;
+		reserved = set;
 
 		// global objects
 		tags = (config != null) && config.containsKey("globals") ?
 				config.getString("globals").split(",") : new String[0];
-		map = new HashMap<String, Boolean>(tags.length);
+		set = new HashSet<String>(tags.length);
 		for (String value : tags) {
-			map.put(value, true);
+			set.add(value);
 		}
-		globals = map;
+		globals = set;
 
 		// object properties
 		tags = (config != null) && config.containsKey("properties") ?
 				config.getString("properties").split(",") : new String[0];
-		map = new HashMap<String, Boolean>(tags.length);
+		set = new HashSet<String>(tags.length);
 		for (String value : tags) {
-			map.put(value, true);
+			set.add(value);
 		}
-		properties = map;
+		properties = set;
 
 		// browser objects
 		tags = (config != null) && config.containsKey("browser") ?
 				config.getString("browser").split(",") : new String[0];
-		map = new HashMap<String, Boolean>(tags.length);
+		set = new HashSet<String>(tags.length);
 		for (String value : tags) {
-			map.put(value, true);
+			set.add(value);
 		}
-		browser = map;
+		browser = set;
 	}
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.