gnodet commented on code in PR #1386:
URL: https://github.com/apache/maven/pull/1386#discussion_r1459299775


##########
maven-xml-impl/src/main/java/org/apache/maven/internal/xml/ImmutableCollections.java:
##########
@@ -0,0 +1,601 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.internal.xml;
+
+import java.io.Serializable;
+import java.util.*;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
+
+class ImmutableCollections {

Review Comment:
   The same classes are used in the immutable classes generated from the 
modello schemas.
   Those are similar to the new `Map.of()` and `List.of()` in recent JDKs.
   The main benefit is that there's no copy if you ask for an immutable 
collection if you pass an already immutable collection (this list is always 
wrapped in JDK 8) and there's no safe copy, i.e. the unmodifiable collection is 
just a wrapper on top of the collection, so it's still can be modified, so one 
needs to do a copy first.
   Bottom line, the current code is actually using 
`Collections.unmodifiableMap(new HashMap<>(attributes))` which is quite 
expensive.
   
   If we were to raise the runtime requirement to JDK 9, I'd happily get rid of 
those.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to