Skip to content

Commit dc6cbde

Browse files
alex-on-javaThomas Darimont
authored andcommitted
DATAMONGO-1147 - Remove manual array copy.
Remove manual array coping by using Arrays.copyOf(values, values.length). Original pull request: spring-projects#258.
1 parent aaaf7e5 commit dc6cbde

File tree

2 files changed

+5
-24
lines changed

2 files changed

+5
-24
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/BasicUpdate.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.mongodb.core.query;
1717

18+
import java.util.Arrays;
1819
import java.util.Collections;
1920

2021
import com.mongodb.BasicDBObject;
@@ -87,12 +88,8 @@ public Update pull(String key, Object value) {
8788

8889
@Override
8990
public Update pullAll(String key, Object[] values) {
90-
Object[] convertedValues = new Object[values.length];
91-
for (int i = 0; i < values.length; i++) {
92-
convertedValues[i] = values[i];
93-
}
9491
DBObject keyValue = new BasicDBObject();
95-
keyValue.put(key, convertedValues);
92+
keyValue.put(key, Arrays.copyOf(values, values.length));
9693
updateObject.put("$pullAll", keyValue);
9794
return this;
9895
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,7 @@ public PushOperatorBuilder push(String key) {
189189
* @return
190190
*/
191191
public Update pushAll(String key, Object[] values) {
192-
193-
Object[] convertedValues = new Object[values.length];
194-
for (int i = 0; i < values.length; i++) {
195-
convertedValues[i] = values[i];
196-
}
197-
addMultiFieldOperation("$pushAll", key, convertedValues);
192+
addMultiFieldOperation("$pushAll", key, Arrays.copyOf(values, values.length));
198193
return this;
199194
}
200195

@@ -258,12 +253,7 @@ public Update pull(String key, Object value) {
258253
* @return
259254
*/
260255
public Update pullAll(String key, Object[] values) {
261-
262-
Object[] convertedValues = new Object[values.length];
263-
for (int i = 0; i < values.length; i++) {
264-
convertedValues[i] = values[i];
265-
}
266-
addFieldOperation("$pullAll", key, convertedValues);
256+
addFieldOperation("$pullAll", key, Arrays.copyOf(values, values.length));
267257
return this;
268258
}
269259

@@ -467,13 +457,7 @@ private Object[] extractValues(Object[] values) {
467457
return ((Collection<?>) values[0]).toArray();
468458
}
469459

470-
Object[] convertedValues = new Object[values.length];
471-
472-
for (int i = 0; i < values.length; i++) {
473-
convertedValues[i] = values[i];
474-
}
475-
476-
return convertedValues;
460+
return Arrays.copyOf(values, values.length);
477461
}
478462

479463
/*

0 commit comments

Comments
 (0)