cpoerschke commented on a change in pull request #243:
URL: https://github.com/apache/solr/pull/243#discussion_r692345700
##########
File path: solr/solrj/src/java/org/apache/solr/client/solrj/io/Tuple.java
##########
@@ -87,10 +87,20 @@ public Tuple(String k1, Object v1, String k2, Object v2) {
* @param fields map containing keys and values to be copied to this tuple
*/
public Tuple(Map<String, ?> fields) {
- // TODO Use bulk putAll operation that will properly size the map
- // https://issues.apache.org/jira/browse/SOLR-15480
- for (Map.Entry<String, ?> entry : fields.entrySet()) {
- put(entry.getKey(), entry.getValue());
+ putAll(fields);
+ }
+
+ /**
+ * A copy constructor
+ * @param original Tuple that will be copied
+ */
+ public Tuple(Tuple original) {
+ this.putAll(original.fields);
+ if (original.fieldNames != null) {
+ this.fieldNames = new ArrayList<>(original.fieldNames);
+ }
+ if (original.fieldLabels != null) {
+ this.fieldLabels = new HashMap<>(original.fieldLabels);
Review comment:
> ... What if there is overlap between the two field names lists? ...
> ... What if there is overlap between the two field labels maps? ...
> ... The use of field labels and field names seems relatively rare. ...
So it seems there's currently no `getFieldLabels()` or `getFieldNames()` use
in the code base and looking at the use within the `Tuple.writeMap` method I
think we don't need to worry about hypothetically a sorted map turning into an
unsorted map via merging or cloning i.e. we can go with the `ArrayList` and
`HashMap` as it is, sorry for the distraction and diversion into cloning and
reflection territory ...
Interestingly though the `Tuple.writeMap` method uses `EntryWriter.put` that
mentions to not call it twice with the same key --
https://github.com/apache/lucene-solr/blob/releases/lucene-solr/8.9.0/solr/solrj/src/java/org/apache/solr/common/MapWriter.java#L87
-- and so the overlap when merging question seems relevant, there's no
`TupleTest` class as yet but maybe there's an opportunity here to start one?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]