MCPcopy Create free account
hub / github.com/grpc/grpc-java / removeAll

Method removeAll

api/src/main/java/io/grpc/Metadata.java:402–424  ·  view source on GitHub ↗

Remove all values for the given key. If there were no values, null is returned.

(Key<T> key)

Source from the content-addressed store, hash-verified

400
401 /** Remove all values for the given key. If there were no values, {@code null} is returned. */
402 public <T> Iterable<T> removeAll(Key<T> key) {
403 if (isEmpty()) {
404 return null;
405 }
406 int writeIdx = 0;
407 int readIdx = 0;
408 List<T> ret = null;
409 for (; readIdx < size; readIdx++) {
410 if (bytesEqual(key.asciiName(), name(readIdx))) {
411 ret = ret != null ? ret : new ArrayList<T>();
412 ret.add(valueAsT(readIdx, key));
413 continue;
414 }
415 name(writeIdx, name(readIdx));
416 value(writeIdx, value(readIdx));
417 writeIdx++;
418 }
419 int newSize = writeIdx;
420 // Multiply by two since namesAndValues is interleaved.
421 Arrays.fill(namesAndValues, writeIdx * 2, len(), null);
422 size = newSize;
423 return ret;
424 }
425
426 /**
427 * Remove all values for the given key without returning them. This is a minor performance

Callers 3

testMutationsMethod · 0.95

Calls 9

isEmptyMethod · 0.95
bytesEqualMethod · 0.95
nameMethod · 0.95
valueAsTMethod · 0.95
valueMethod · 0.95
lenMethod · 0.95
asciiNameMethod · 0.80
fillMethod · 0.80
addMethod · 0.65

Tested by 2

testMutationsMethod · 0.76