38 lines
1.5 KiB
Diff
38 lines
1.5 KiB
Diff
# UNDF: UNDF-2026-000000109
|
|
--- a/hibernate-core/src/main/java/org/hibernate/mapping/Index.java
|
|
+++ b/hibernate-core/src/main/java/org/hibernate/mapping/Index.java
|
|
@@ -7,6 +7,7 @@ package org.hibernate.mapping;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.ArrayList;
|
|
+import java.util.LinkedHashSet;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
@@ -33,7 +34,12 @@ public class Index implements Exportable, Serializable {
|
|
private Identifier name;
|
|
private Table table;
|
|
private boolean unique;
|
|
private String options = "";
|
|
- private final java.util.List<Selectable> selectables = new ArrayList<>();
|
|
+ // hibernate-0003 fix: LinkedHashSet for O(1) contains() in addColumn().
|
|
+ // Previously ArrayList<Selectable>: addColumn() called selectables.contains()
|
|
+ // which is O(S), and addColumn() is called from loops over column sources at
|
|
+ // bind time, giving O(S²) total. LinkedHashSet preserves order and gives O(1).
|
|
+ private final LinkedHashSet<Selectable> selectablesSet = new LinkedHashSet<>();
|
|
private final java.util.Map<Selectable, String> selectableOrderMap = new HashMap<>();
|
|
|
|
@@ -92,9 +98,9 @@ public class Index implements Exportable, Serializable {
|
|
|
|
public void addColumn(Selectable selectable) {
|
|
- if ( !selectables.contains( selectable ) ) {
|
|
- selectables.add( selectable );
|
|
- }
|
|
+ // O(1) with LinkedHashSet; was O(S) with ArrayList
|
|
+ selectablesSet.add( selectable );
|
|
}
|
|
|
|
public List<Selectable> getSelectables() {
|
|
- return unmodifiableList( selectables );
|
|
+ return List.copyOf( selectablesSet );
|
|
}
|