Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Unnecessary Hashtable usage in CSS.styleConstantToCssMap #23149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 36 additions & 34 deletions src/java.desktop/share/classes/javax/swing/text/html/CSS.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2024, 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
Expand Down Expand Up @@ -1097,7 +1097,7 @@ private static int getTableBorder(AttributeSet tableAttr) {
* up a translation from StyleConstants (i.e. the <em>well known</em>
* attributes) to the associated CSS attributes.
*/
private static final Hashtable<Object, Attribute> styleConstantToCssMap = new Hashtable<Object, Attribute>(17);
private static final Map<Object, Attribute> styleConstantToCssMap;
/** Maps from HTML value to a CSS value. Used in internal mapping. */
private static final Hashtable<String, CSS.Value> htmlValueToCssValueMap = new Hashtable<String, CSS.Value>(8);
/** Maps from CSS value (string) to internal value. */
Expand Down Expand Up @@ -1167,38 +1167,40 @@ private static int getTableBorder(AttributeSet tableAttr) {
);

// initialize StyleConstants mapping
styleConstantToCssMap.put(StyleConstants.FontFamily,
CSS.Attribute.FONT_FAMILY);
styleConstantToCssMap.put(StyleConstants.FontSize,
CSS.Attribute.FONT_SIZE);
styleConstantToCssMap.put(StyleConstants.Bold,
CSS.Attribute.FONT_WEIGHT);
styleConstantToCssMap.put(StyleConstants.Italic,
CSS.Attribute.FONT_STYLE);
styleConstantToCssMap.put(StyleConstants.Underline,
CSS.Attribute.TEXT_DECORATION);
styleConstantToCssMap.put(StyleConstants.StrikeThrough,
CSS.Attribute.TEXT_DECORATION);
styleConstantToCssMap.put(StyleConstants.Superscript,
CSS.Attribute.VERTICAL_ALIGN);
styleConstantToCssMap.put(StyleConstants.Subscript,
CSS.Attribute.VERTICAL_ALIGN);
styleConstantToCssMap.put(StyleConstants.Foreground,
CSS.Attribute.COLOR);
styleConstantToCssMap.put(StyleConstants.Background,
CSS.Attribute.BACKGROUND_COLOR);
styleConstantToCssMap.put(StyleConstants.FirstLineIndent,
CSS.Attribute.TEXT_INDENT);
styleConstantToCssMap.put(StyleConstants.LeftIndent,
CSS.Attribute.MARGIN_LEFT);
styleConstantToCssMap.put(StyleConstants.RightIndent,
CSS.Attribute.MARGIN_RIGHT);
styleConstantToCssMap.put(StyleConstants.SpaceAbove,
CSS.Attribute.MARGIN_TOP);
styleConstantToCssMap.put(StyleConstants.SpaceBelow,
CSS.Attribute.MARGIN_BOTTOM);
styleConstantToCssMap.put(StyleConstants.Alignment,
CSS.Attribute.TEXT_ALIGN);
styleConstantToCssMap = Map.ofEntries(
Map.entry(StyleConstants.FontFamily,
CSS.Attribute.FONT_FAMILY),
Map.entry(StyleConstants.FontSize,
CSS.Attribute.FONT_SIZE),
Map.entry(StyleConstants.Bold,
CSS.Attribute.FONT_WEIGHT),
Map.entry(StyleConstants.Italic,
CSS.Attribute.FONT_STYLE),
Map.entry(StyleConstants.Underline,
CSS.Attribute.TEXT_DECORATION),
Map.entry(StyleConstants.StrikeThrough,
CSS.Attribute.TEXT_DECORATION),
Map.entry(StyleConstants.Superscript,
CSS.Attribute.VERTICAL_ALIGN),
Map.entry(StyleConstants.Subscript,
CSS.Attribute.VERTICAL_ALIGN),
Map.entry(StyleConstants.Foreground,
CSS.Attribute.COLOR),
Map.entry(StyleConstants.Background,
CSS.Attribute.BACKGROUND_COLOR),
Map.entry(StyleConstants.FirstLineIndent,
CSS.Attribute.TEXT_INDENT),
Map.entry(StyleConstants.LeftIndent,
CSS.Attribute.MARGIN_LEFT),
Map.entry(StyleConstants.RightIndent,
CSS.Attribute.MARGIN_RIGHT),
Map.entry(StyleConstants.SpaceAbove,
CSS.Attribute.MARGIN_TOP),
Map.entry(StyleConstants.SpaceBelow,
CSS.Attribute.MARGIN_BOTTOM),
Map.entry(StyleConstants.Alignment,
CSS.Attribute.TEXT_ALIGN)
);

// HTML->CSS
htmlValueToCssValueMap.put("disc", CSS.Value.DISC);
Expand Down