Skip to content

Commit 6ce8d82

Browse files
authored
Merge branch '3.x' into perf-issues
2 parents b478bb7 + e4d3964 commit 6ce8d82

10 files changed

Lines changed: 43 additions & 73 deletions

File tree

csv/src/main/java/tools/jackson/dataformat/csv/CsvSchema.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ public CsvSchema(Column[] columns, int features,
10571057

10581058
// and then we may need to create a mapping
10591059
if (_columns.length == 0) {
1060-
_columnsByName = Collections.emptyMap();
1060+
_columnsByName = Map.of();
10611061
} else {
10621062
_columnsByName = new LinkedHashMap<>(4 + _columns.length);
10631063
for (Column c : _columns) {
@@ -1106,7 +1106,7 @@ protected CsvSchema(CsvSchema base, Column[] columns)
11061106

11071107
// and then we may need to create a mapping
11081108
if (_columns.length == 0) {
1109-
_columnsByName = Collections.emptyMap();
1109+
_columnsByName = Map.of();
11101110
} else {
11111111
_columnsByName = new LinkedHashMap<>(4 + _columns.length);
11121112
for (Column c : _columns) {
@@ -1636,7 +1636,7 @@ public String getNullValueString() {
16361636

16371637
@Override
16381638
public Iterator<Column> iterator() {
1639-
return Arrays.asList(_columns).iterator();
1639+
return List.of(_columns).iterator();
16401640
}
16411641

16421642
/**

csv/src/main/java/tools/jackson/dataformat/csv/impl/CsvDecoder.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,18 +1070,13 @@ protected char _unescape() throws JacksonException {
10701070
}
10711071
// Some characters are more special than others, so:
10721072
char c = _inputBuffer[_inputPtr++];
1073-
switch (c) {
1074-
case '0':
1075-
return '\0';
1076-
case 'n':
1077-
return '\n';
1078-
case 'r':
1079-
return '\r';
1080-
case 't':
1081-
return '\t';
1082-
}
1083-
// others, return as is...
1084-
return c;
1073+
return switch (c) {
1074+
case '0' -> '\0';
1075+
case 'n' -> '\n';
1076+
case 'r' -> '\r';
1077+
case 't' -> '\t';
1078+
default -> c;
1079+
};
10851080
}
10861081

10871082
protected final int _nextChar() throws JacksonException {

csv/src/main/java/tools/jackson/dataformat/csv/impl/UTF8Reader.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,7 @@ private boolean loadMore(int available) throws IOException
420420
if (_inputPtr > 0) {
421421
// Can only do so if buffer mutable
422422
if (!_inputBufferReadOnly) {
423-
for (int i = 0; i < available; ++i) {
424-
_inputBuffer[i] = _inputBuffer[_inputPtr+i];
425-
}
423+
System.arraycopy(_inputBuffer, _inputPtr, _inputBuffer, 0, available);
426424
_inputPtr = 0;
427425
_inputEnd = available;
428426
}

release-notes/VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ implementations)
2020
(requested by @OrangeDog)
2121
(fix by @seonwooj0810)
2222

23-
3.2.2 (not yet released)
23+
3.2.2 (14-Aug-2026)
2424

2525
#701: (yaml) `ALWAYS_QUOTE_NUMBERS_AS_STRINGS` does not quote exponent (`1e5`)
2626
and non-finite (`.inf`, `.nan`) number forms
@@ -125,7 +125,7 @@ No changes since 3.2.1
125125
#685: (toml) Improve TOML 1.1.0 compatibility (parsing)
126126
(fix by @yawkat)
127127

128-
3.1.6 (not yet released)
128+
3.1.6 (14-Aug-2026)
129129

130130
#701: (yaml) `ALWAYS_QUOTE_NUMBERS_AS_STRINGS` does not quote exponent (`1e5`)
131131
and non-finite (`.inf`, `.nan`) number forms

toml/src/main/java/tools/jackson/dataformat/toml/UTF8Reader.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,7 @@ private boolean loadMore(int available) throws IOException
350350
if (_inputPtr > 0) {
351351
// Can only do so if buffer mutable
352352
if (!_inputBufferReadOnly) {
353-
for (int i = 0; i < available; ++i) {
354-
_inputBuffer[i] = _inputBuffer[_inputPtr+i];
355-
}
353+
System.arraycopy(_inputBuffer, _inputPtr, _inputBuffer, 0, available);
356354
_inputPtr = 0;
357355
_inputEnd = available;
358356
}

yaml/src/main/java/tools/jackson/dataformat/yaml/UTF8Reader.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,7 @@ private boolean loadMore(int available) throws IOException
457457
if (_inputPtr > 0) {
458458
// Can only do so if buffer mutable
459459
if (!_inputBufferReadOnly) {
460-
for (int i = 0; i < available; ++i) {
461-
_inputBuffer[i] = _inputBuffer[_inputPtr+i];
462-
}
460+
System.arraycopy(_inputBuffer, _inputPtr, _inputBuffer, 0, available);
463461
_inputPtr = 0;
464462
_inputEnd = available;
465463
}

yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLFactory.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.snakeyaml.engine.v2.schema.CoreSchema;
1010
import org.snakeyaml.engine.v2.schema.FailsafeSchema;
1111
import org.snakeyaml.engine.v2.schema.JsonSchema;
12+
import org.snakeyaml.engine.v2.schema.Schema;
1213

1314
import tools.jackson.core.*;
1415
import tools.jackson.core.base.TextualTSFactory;
@@ -139,18 +140,14 @@ protected YAMLFactory(YAMLFactoryBuilder b)
139140
if (b.loadSettings() == null) {
140141
LoadSettingsBuilder builder = LoadSettings.builder();
141142
if (_schema != null) {
142-
switch (_schema) {
143-
case FAILSAFE:
144-
builder.setSchema(new FailsafeSchema());
145-
break;
146-
case JSON:
147-
builder.setSchema(new JsonSchema());
148-
break;
149-
case CORE:
150-
builder.setSchema(new CoreSchema());
151-
break;
152-
default:
153-
break;
143+
Schema s = switch (_schema) {
144+
case FAILSAFE -> new FailsafeSchema();
145+
case JSON -> new JsonSchema();
146+
case CORE -> new CoreSchema();
147+
default -> null;
148+
};
149+
if (s != null) {
150+
builder.setSchema(s);
154151
}
155152
}
156153
_loadSettings = builder.build();

yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLGenerator.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,8 @@ public JsonGenerator writeStartArray() throws JacksonException
407407
FlowStyle style = _outputOptions.getDefaultFlowStyle();
408408
String yamlTag = _typeId;
409409
boolean implicit = (yamlTag == null);
410-
Optional<Anchor> anchor = Optional.ofNullable(_objectId).map(s -> new Anchor(s));
411-
if (anchor.isPresent()) {
412-
_objectId = null;
413-
}
410+
Optional<Anchor> anchor = Optional.ofNullable(_objectId).map(Anchor::new);
411+
_objectId = null;
414412
_emit(new SequenceStartEvent(anchor, Optional.ofNullable(yamlTag),
415413
implicit, style));
416414
return this;
@@ -445,10 +443,8 @@ public JsonGenerator writeStartObject() throws JacksonException
445443
FlowStyle style = _outputOptions.getDefaultFlowStyle();
446444
String yamlTag = _typeId;
447445
boolean implicit = (yamlTag == null);
448-
Optional<Anchor> anchor = Optional.ofNullable(_objectId).map(s -> new Anchor(s));
449-
if (anchor.isPresent()) {
450-
_objectId = null;
451-
}
446+
Optional<Anchor> anchor = Optional.ofNullable(_objectId).map(Anchor::new);
447+
_objectId = null;
452448
_emit(new MappingStartEvent(anchor, Optional.ofNullable(yamlTag), implicit, style));
453449
return this;
454450
}
@@ -926,10 +922,8 @@ protected ScalarEvent _scalarEvent(String value, ScalarStyle style)
926922
if (yamlTag != null) {
927923
_typeId = null;
928924
}
929-
Optional<Anchor> anchor = Optional.ofNullable(_objectId).map(s -> new Anchor(s));
930-
if (anchor.isPresent()) {
931-
_objectId = null;
932-
}
925+
Optional<Anchor> anchor = Optional.ofNullable(_objectId).map(Anchor::new);
926+
_objectId = null;
933927
// 29-Nov-2017, tatu: Not 100% sure why we don't force explicit tags for
934928
// type id, but trying to do so seems to double up tag output...
935929
return new ScalarEvent(anchor, Optional.ofNullable(yamlTag), NO_TAGS, value, style);
@@ -941,7 +935,7 @@ protected String _lf() {
941935

942936
protected void _emitStartDocument() throws JacksonException
943937
{
944-
Map<String,String> noTags = Collections.emptyMap();
938+
Map<String,String> noTags = Map.of();
945939
boolean startMarker = YAMLWriteFeature.WRITE_DOC_START_MARKER.enabledIn(_formatWriteFeatures);
946940
_emit(new DocumentStartEvent(startMarker, _outputOptions.getYamlDirective(),
947941
// for 1.10 was: ((version == null) ? null : version.getArray()),

yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLParser.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,12 @@ public TokenStreamLocation currentLocation() {
283283

284284
protected TokenStreamLocation _locationFor(Optional<Mark> option)
285285
{
286-
if (!option.isPresent()) {
287-
return new TokenStreamLocation(_ioContext.contentReference(),
288-
-1, -1, -1);
289-
}
290-
Mark m = option.get();
291-
return new TokenStreamLocation(_ioContext.contentReference(),
286+
return option.map(m -> new TokenStreamLocation(_ioContext.contentReference(),
292287
m.getIndex(),
293288
m.getLine() + 1, // from 0- to 1-based
294-
m.getColumn() + 1); // ditto
289+
m.getColumn() + 1)) // ditto
290+
.orElseGet(() -> new TokenStreamLocation(_ioContext.contentReference(),
291+
-1, -1, -1));
295292
}
296293

297294
// Note: SHOULD override 'getTokenLineNr', 'getTokenColumnNr', but those are final in 2.0
@@ -502,7 +499,7 @@ protected JsonToken _decodeScalar(ScalarEvent scalar) throws JacksonException
502499
// we may get an explicit tag, if so, use for corroborating...
503500
Optional<String> typeTagOptional = scalar.getTag();
504501
final int len = value.length();
505-
if (!typeTagOptional.isPresent() || typeTagOptional.get().equals("!")) { // no, implicit
502+
if (typeTagOptional.filter(t -> !t.equals("!")).isEmpty()) { // no, implicit
506503
Tag nodeTag = _yamlResolver.resolve(value, scalar.getImplicit().canOmitTagInPlainScalar());
507504
if (nodeTag == Tag.STR) {
508505
return JsonToken.VALUE_STRING;
@@ -579,16 +576,11 @@ protected JsonToken _decodeScalar(ScalarEvent scalar) throws JacksonException
579576

580577
protected Boolean _matchYAMLBoolean(String value, int len)
581578
{
582-
switch (len) {
583-
case 4:
584-
//TODO it should be only lower case
585-
if ("true".equalsIgnoreCase(value)) return Boolean.TRUE;
586-
break;
587-
case 5:
588-
if ("false".equalsIgnoreCase(value)) return Boolean.FALSE;
589-
break;
590-
}
591-
return null;
579+
return switch (len) {
580+
case 4 -> "true".equalsIgnoreCase(value) ? Boolean.TRUE : null;
581+
case 5 -> "false".equalsIgnoreCase(value) ? Boolean.FALSE : null;
582+
default -> null;
583+
};
592584
}
593585

594586
protected JsonToken _decodeNumberScalar(String value, final int len)

yaml/src/main/java/tools/jackson/dataformat/yaml/util/StringQuotingChecker.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package tools.jackson.dataformat.yaml.util;
22

3-
import java.util.Arrays;
4-
import java.util.HashSet;
53
import java.util.Set;
64

75
/**
@@ -23,7 +21,7 @@ public abstract class StringQuotingChecker
2321
* and <a href="https://yaml.org/type/bool.html">boolean</a> type specs,
2422
* better retain quoting for some keys (property names) and values.
2523
*/
26-
private final static Set<String> RESERVED_KEYWORDS = new HashSet<>(Arrays.asList(
24+
private final static Set<String> RESERVED_KEYWORDS = Set.of(
2725
// 02-Apr-2019, tatu: Some names will look funny if escaped: let's leave out
2826
// single letter case (esp so 'y' won't get escaped)
2927
// 17-Sep-2020, tatu: [dataformats-text#226] No, let's be consistent w/ values
@@ -36,7 +34,7 @@ public abstract class StringQuotingChecker
3634
"true", "True", "TRUE",
3735
"y", "Y",
3836
"yes", "Yes", "YES"
39-
));
37+
);
4038

4139
/**
4240
* Method called by

0 commit comments

Comments
 (0)