Skip to content

Avoid collection copying #4553

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

/**
Expand Down Expand Up @@ -405,7 +406,7 @@ private List<JobExecution> getJobExecutionsWithStatusGreaterThan(String jobIdent

for (JobInstance jobInstance : lastInstances) {
List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);
if (jobExecutions == null || jobExecutions.isEmpty()) {
if (CollectionUtils.isEmpty(jobExecutions)) {
continue;
}
for (JobExecution jobExecution : jobExecutions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
*/
public class Chunk<W> implements Iterable<W>, Serializable {

private List<W> items = new ArrayList<>();
private final List<W> items = new ArrayList<>();

private List<SkipWrapper<W>> skips = new ArrayList<>();
private final List<SkipWrapper<W>> skips = new ArrayList<>();

private final List<Exception> errors = new ArrayList<>();

Expand All @@ -67,10 +67,10 @@ public Chunk(List<? extends W> items) {
public Chunk(List<? extends W> items, List<SkipWrapper<W>> skips) {
super();
if (items != null) {
this.items = new ArrayList<>(items);
this.items.addAll(items);
}
if (skips != null) {
this.skips = new ArrayList<>(skips);
this.skips.addAll(skips);
}
}

Expand Down Expand Up @@ -103,7 +103,7 @@ public void clear() {
* @return a copy of the items to be processed as an unmodifiable list
*/
public List<W> getItems() {
return List.copyOf(items);
return Collections.unmodifiableList(items);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void write(Chunk<? extends T> chunk) throws Exception {
* @param chunk the chunk of items to be persisted.
*/
protected void doWrite(Chunk<? extends T> chunk) {
if (!CollectionUtils.isEmpty(chunk.getItems())) {
if (!chunk.isEmpty()) {
switch (this.mode) {
case INSERT -> insert(chunk);
case REMOVE -> remove(chunk);
Expand Down Expand Up @@ -263,7 +263,7 @@ private Chunk<T> getCurrentBuffer() {
public void beforeCommit(boolean readOnly) {
Chunk<T> chunk = (Chunk<T>) TransactionSynchronizationManager.getResource(bufferKey);

if (!CollectionUtils.isEmpty(chunk.getItems())) {
if (!chunk.isEmpty()) {
if (!readOnly) {
doWrite(chunk);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void afterPropertiesSet() throws Exception {
*/
@Override
public void write(Chunk<? extends T> chunk) throws Exception {
if (!CollectionUtils.isEmpty(chunk.getItems())) {
if (!chunk.isEmpty()) {
doWrite(chunk);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void setRepository(CrudRepository<T, ?> repository) {
*/
@Override
public void write(Chunk<? extends T> chunk) throws Exception {
if (!CollectionUtils.isEmpty(chunk.getItems())) {
if (!chunk.isEmpty()) {
doWrite(chunk);
}
}
Expand Down