Commit a113feb2 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Add new method to retrieve raw descriptor length.

When we switched from storing copies of byte[] to storing byte[]
references, offset, and length, getRawDescriptor() suddenly became
more expensive than before.  (Before that, copying bytes in the first
place was always expensive.)  If an application only calls
Descriptor#getRawDescriptorBytes() to learn the array length, there's
now a more efficient way to provide that information.
parent 1062da63
......@@ -12,6 +12,9 @@
* Medium changes
- Let DescriptorParser return an Iterable instead of a List, which
prepares parsing large descriptor files descriptor by descriptor.
- Add new method to retrieve the raw descriptor length, rather than
forcing applications to request (a copy of) raw descriptor bytes
only to determine the raw descriptor length.
* Minor changes
- Fix a bug where NetworkStatusEntry's getMicrodescriptorDigests()
......
......@@ -17,10 +17,25 @@ public interface Descriptor {
/**
* Return the raw descriptor bytes.
*
* <p>This method creates a new copy of raw descriptor bytes from a
* potentially larger byte array containing multiple descriptors.
* Applications that only want to learn about raw descriptor length in bytes
* should instead use {@link #getRawDescriptorLength()}.</p>
*
* @since 1.0.0
*/
public byte[] getRawDescriptorBytes();
/**
* Return the raw descriptor length in bytes.
*
* <p>Returns the exact same result as {@code getRawDescriptorBytes().length},
* but much more efficiently.</p>
*
* @since 1.9.0
*/
public int getRawDescriptorLength();
/**
* Return the (possibly empty) list of annotations in the format
* {@code "@key( value)*"}.
......
......@@ -41,6 +41,11 @@ public abstract class DescriptorImpl implements Descriptor {
*/
protected int length;
@Override
public int getRawDescriptorLength() {
return this.length;
}
/**
* Optional reference to the descriptor file, if this descriptor was read from
* a descriptor file.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment