Optimize MediaType(MediaType, Charset) constructor

Prior to this commit, the `MediaType` and `MimeType` "copy" constructors
would not leverage the fact that the existing instance has been
validated already (types, subtype and parameters have been checked
already for errors) and the entire validation would be performed again.
This would also allocate map instances in the process.

This commit ensures that the already validated information is reused
directly and that we avoid unnessecary operations and allocations for
such constructors.

Closes gh-36318
This commit is contained in:
Brian Clozel
2026-02-13 14:49:34 +01:00
parent e98c2fe488
commit 97e96895db
2 changed files with 52 additions and 41 deletions
@@ -458,7 +458,7 @@ public class MediaType extends MimeType implements Serializable {
* @throws IllegalArgumentException if any of the parameters contain illegal characters
*/
public MediaType(MediaType other, @Nullable Map<String, String> parameters) {
super(other.getType(), other.getSubtype(), parameters);
super(other, parameters);
}
/**