Add maybeUpdateDataRegion() for efficient data handling
This commit introduces the maybeUpdateDataRegion() helper method,
allowing data to be added directly to the data region without generating
a datacopy instruction. This enables more efficient memory management in
certain scenarios by optimizing data placement.
Test: TH
Change-Id: I97146aa1a93626fd4c0537178d686dd2fa31d744
diff --git a/src/android/net/apf/ApfV6GeneratorBase.java b/src/android/net/apf/ApfV6GeneratorBase.java
index c67ca91..498d3b3 100644
--- a/src/android/net/apf/ApfV6GeneratorBase.java
+++ b/src/android/net/apf/ApfV6GeneratorBase.java
@@ -270,6 +270,18 @@
}
/**
+ * Add the content to the data region if it wasn't exist.
+ */
+ public final Type maybeUpdateDataRegion(@NonNull byte[] content)
+ throws IllegalInstructionException {
+ if (mInstructions.isEmpty()) {
+ throw new IllegalInstructionException("There are no instructions");
+ }
+ mInstructions.get(0).maybeUpdateBytesImm(content, 0, content.length);
+ return self();
+ }
+
+ /**
* Add an instruction to the end of the program to copy data from APF program/data region to
* output buffer and auto-increment the output buffer pointer.
*