diff options
author | Maciej Żenczykowski <maze@google.com> | 2023-08-21 17:42:31 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-08-21 17:42:31 +0000 |
commit | 51556bc5166ee0e668895c2350c0efa02b5de7d8 (patch) | |
tree | 55b0f5724cc1d13b889fb4c42372e028e044ee68 | |
parent | 15a300a8ae797551d944fa5740a7d600066a8db4 (diff) | |
parent | e1fef5a6188890472fb51a02ef000bd45d98fc34 (diff) | |
download | net-51556bc5166ee0e668895c2350c0efa02b5de7d8.tar.gz |
Merge "BpfMap.java - remove getRawValue()" into main am: e1fef5a618
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/2718793
Change-Id: Ibf8107457db684186f68b352e1f6e9d0a5bdb347
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | common/device/com/android/net/module/util/BpfMap.java | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/common/device/com/android/net/module/util/BpfMap.java b/common/device/com/android/net/module/util/BpfMap.java index 9df2b035..b3451c11 100644 --- a/common/device/com/android/net/module/util/BpfMap.java +++ b/common/device/com/android/net/module/util/BpfMap.java @@ -233,30 +233,23 @@ public class BpfMap<K extends Struct, V extends Struct> implements IBpfMap<K, V> public boolean containsKey(@NonNull K key) throws ErrnoException { Objects.requireNonNull(key); - final byte[] rawValue = getRawValue(key.writeToBytes()); - return rawValue != null; + byte[] rawValue = new byte[mValueSize]; + return nativeFindMapEntry(mMapFd.getFd(), key.writeToBytes(), rawValue); } /** Retrieve a value from the map. Return null if there is no such key. */ @Override public V getValue(@NonNull K key) throws ErrnoException { Objects.requireNonNull(key); - final byte[] rawValue = getRawValue(key.writeToBytes()); - if (rawValue == null) return null; + byte[] rawValue = new byte[mValueSize]; + if (!nativeFindMapEntry(mMapFd.getFd(), key.writeToBytes(), rawValue)) return null; final ByteBuffer buffer = ByteBuffer.wrap(rawValue); buffer.order(ByteOrder.nativeOrder()); return Struct.parse(mValueClass, buffer); } - private byte[] getRawValue(final byte[] key) throws ErrnoException { - byte[] value = new byte[mValueSize]; - if (nativeFindMapEntry(mMapFd.getFd(), key, value)) return value; - - return null; - } - /** * Iterate through the map and handle each key -> value retrieved base on the given BiConsumer. * The given BiConsumer may to delete the passed-in entry, but is not allowed to perform any |