You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/08/20 13:14:48 UTC
[lucene-solr] 02/03: @577 A little more efficient.
This is an automated email from the ASF dual-hosted git repository.
markrmiller pushed a commit to branch reference_impl_dev
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit 1f36dbc8936fb3a175ede70f56b16683836d9ec4
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Thu Aug 20 06:10:13 2020 -0500
@577 A little more efficient.
---
.../src/java/org/apache/solr/common/ParWork.java | 37 +++++-----------------
1 file changed, 8 insertions(+), 29 deletions(-)
diff --git a/solr/solrj/src/java/org/apache/solr/common/ParWork.java b/solr/solrj/src/java/org/apache/solr/common/ParWork.java
index c39596f..b748fb3 100644
--- a/solr/solrj/src/java/org/apache/solr/common/ParWork.java
+++ b/solr/solrj/src/java/org/apache/solr/common/ParWork.java
@@ -330,36 +330,12 @@ public class ParWork implements Closeable {
@SuppressWarnings({ "unchecked", "rawtypes" })
private void gatherObjects(Object object, List<ParObject> objects) {
- if (log.isDebugEnabled()) {
- log.debug("gatherObjects(Object object={}, List<Object> objects={}) - start", object, objects);
- }
-
if (object != null) {
- if (object.getClass().isArray()) {
- if (log.isDebugEnabled()) {
- log.debug("Found an array to gather against");
- }
-
- for (Object obj : (Object[]) object) {
- gatherObjects(obj, objects);
- }
-
- } else if (object instanceof Collection) {
- if (log.isDebugEnabled()) {
- log.debug("Found a Collection to gather against");
- }
+ if (object instanceof Collection) {
for (Object obj : (Collection) object) {
gatherObjects(obj, objects);
}
- } else if (object instanceof Map<?, ?>) {
- if (log.isDebugEnabled()) {
- log.debug("Found a Map to gather against");
- }
- ((Map) object).forEach((k, v) -> gatherObjects(v, objects));
} else {
- if (log.isDebugEnabled()) {
- log.debug("Found a non collection object to add {}", object.getClass().getName());
- }
if (object instanceof ParObject) {
objects.add((ParObject) object);
} else {
@@ -376,10 +352,13 @@ public class ParWork implements Closeable {
if (log.isDebugEnabled()) {
log.debug("add(String label={}, Object object={}, Callable Callables={}) - start", object.label, object);
}
-
- List<ParObject> objects = new ArrayList<>();
-
- gatherObjects(object.object, objects);
+ List<ParObject> objects;
+ if (object.object instanceof Collection) {
+ objects = new ArrayList<>(((Collection<?>) object.object).size());
+ gatherObjects(object.object, objects);
+ } else {
+ objects = Collections.singletonList(object);
+ }
WorkUnit workUnit = new WorkUnit(objects, tracker);
workUnits.add(workUnit);