Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: third_party/protobuf/java/src/main/java/com/google/protobuf/LazyStringArrayList.java

Issue 21208003: Update protobuf to r428, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/java/src/main/java/com/google/protobuf/LazyStringArrayList.java
===================================================================
--- third_party/protobuf/java/src/main/java/com/google/protobuf/LazyStringArrayList.java (revision 216642)
+++ third_party/protobuf/java/src/main/java/com/google/protobuf/LazyStringArrayList.java (working copy)
@@ -33,8 +33,9 @@
import java.util.List;
import java.util.AbstractList;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.RandomAccess;
-import java.util.Collection;
/**
* An implementation of {@link LazyStringList} that wraps an ArrayList. Each
@@ -72,6 +73,11 @@
list = new ArrayList<Object>();
}
+ public LazyStringArrayList(LazyStringList from) {
+ list = new ArrayList<Object>(from.size());
+ addAll(from);
+ }
+
public LazyStringArrayList(List<String> from) {
list = new ArrayList<Object>(from);
}
@@ -84,7 +90,7 @@
} else {
ByteString bs = (ByteString) o;
String s = bs.toStringUtf8();
- if (Internal.isValidUtf8(bs)) {
+ if (bs.isValidUtf8()) {
list.set(index, s);
}
return s;
@@ -109,8 +115,21 @@
}
@Override
+ public boolean addAll(Collection<? extends String> c) {
+ // The default implementation of AbstractCollection.addAll(Collection)
+ // delegates to add(Object). This implementation instead delegates to
+ // addAll(int, Collection), which makes a special case for Collections
+ // which are instances of LazyStringList.
+ return addAll(size(), c);
+ }
+
+ @Override
public boolean addAll(int index, Collection<? extends String> c) {
- boolean ret = list.addAll(index, c);
+ // When copying from another LazyStringList, directly copy the underlying
+ // elements rather than forcing each element to be decoded to a String.
+ Collection<?> collection = c instanceof LazyStringList
+ ? ((LazyStringList) c).getUnderlyingElements() : c;
+ boolean ret = list.addAll(index, collection);
modCount++;
return ret;
}
@@ -152,4 +171,9 @@
return ((ByteString) o).toStringUtf8();
}
}
+
+ @Override
+ public List<?> getUnderlyingElements() {
+ return Collections.unmodifiableList(list);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698