From 24de9dee80738fe6ab1fc726b071546c85bbf79a Mon Sep 17 00:00:00 2001 From: Andrey Turbanov Date: Thu, 16 Jan 2025 11:38:28 +0000 Subject: [PATCH] 8347370: Unnecessary Hashtable usage in javax.swing.text.html.HTML Reviewed-by: aivanov, azvegint --- .../classes/javax/swing/text/html/HTML.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/java.desktop/share/classes/javax/swing/text/html/HTML.java b/src/java.desktop/share/classes/javax/swing/text/html/HTML.java index 23e3f089b73..88e12ff8fbc 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/HTML.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/HTML.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,6 +30,7 @@ import java.io.ObjectInputStream; import java.io.Serial; import java.io.Serializable; import java.util.Hashtable; +import java.util.Map; import javax.swing.text.AttributeSet; import javax.swing.text.StyleConstants; @@ -1169,7 +1170,16 @@ public class HTML { private static final Hashtable tagHashtable = new Hashtable(73); /** Maps from StyleConstant key to HTML.Tag. */ - private static final Hashtable scMapping = new Hashtable(8); + private static final Map scMapping = Map.of( + StyleConstants.Bold, Tag.B, + StyleConstants.Italic, Tag.I, + StyleConstants.Underline, Tag.U, + StyleConstants.StrikeThrough, Tag.STRIKE, + StyleConstants.Superscript, Tag.SUP, + StyleConstants.Subscript, Tag.SUB, + StyleConstants.FontFamily, Tag.FONT, + StyleConstants.FontSize, Tag.FONT + ); static { @@ -1185,14 +1195,6 @@ public class HTML { allAttributes[i]); } StyleContext.registerStaticAttributeKey(HTML.NULL_ATTRIBUTE_VALUE); - scMapping.put(StyleConstants.Bold, Tag.B); - scMapping.put(StyleConstants.Italic, Tag.I); - scMapping.put(StyleConstants.Underline, Tag.U); - scMapping.put(StyleConstants.StrikeThrough, Tag.STRIKE); - scMapping.put(StyleConstants.Superscript, Tag.SUP); - scMapping.put(StyleConstants.Subscript, Tag.SUB); - scMapping.put(StyleConstants.FontFamily, Tag.FONT); - scMapping.put(StyleConstants.FontSize, Tag.FONT); } /**