Starlark: inline the method Dict.putAllUnsafe, update the comment
Thanks to unknown commit, the method has a single use and can be inlined. Update the comment to make it more actionable.
RELNOTES: None.
@@ -381,8 +381,15 @@ public final class Dict<K, V>
}
/** Returns a new dict with the specified mutability containing the entries of {@code m}. */
+ @SuppressWarnings("unchecked")
public static <K, V> Dict<K, V> copyOf(@Nullable Mutability mu, Map<? extends K, ? extends V> m) {
- return new Dict<K, V>(mu).putAllUnsafe(m);
+ // TODO(laurentlb): Move this method out of this file and rename it. It should go with
+ // Starlark.fromJava; its main purpose is to convert a Java value to Starlark.
+ Dict<K, V> dict = new Dict<>(mu);
+ for (Map.Entry<?, ?> e : m.entrySet()) {
+ dict.contents.put((K) e.getKey(), (V) Starlark.fromJava(e.getValue(), mu));
+ }
+ return dict;
}
/** Puts the given entry into the dict, without calling {@link #checkMutable}. */
@@ -391,16 +398,6 @@ public final class Dict<K, V>
return this;
}
- /** Puts all entries of the given map into the dict, without calling {@link #checkMutable}. */
- @SuppressWarnings("unchecked")
- private <KK extends K, VV extends V> Dict<K, V> putAllUnsafe(Map<KK, VV> m) {
- for (Map.Entry<KK, VV> e : m.entrySet()) {
- // TODO(adonovan): the fromJava call here is suspicious and inconsistent.
- contents.put(e.getKey(), (VV) Starlark.fromJava(e.getValue(), mutability));
- }
- return this;
- }
-
@Override
public Mutability mutability() {
return mutability;
