pub struct Pool { /* private fields */ }
Expand description
The constant pool found in every java class file.
It is used to have fast lookup for entries and small files.
Removing or modifying items is not allowed
to respect already ‘used’ indices
or to prevent rehashing of the underlying HashMap
.
A Vec
and a HashMap
is used internally to have fast lookups by index and value.
To connect both, Rc
s are used.
As a result, we will have a little overhead, but this should be negligible.
Implementations§
Source§impl Pool
impl Pool
pub fn new() -> Self
pub fn with_capacity(cap: u16) -> Self
Sourcepub fn get(&self, index: u16) -> Result<&Item, Error>
pub fn get(&self, index: u16) -> Result<&Item, Error>
Returns the item at a specified index. If the index is 0 or greater than the size of the pool, an error is returned.
Sourcepub fn get_utf8(&self, index: u16) -> Result<String, Error>
pub fn get_utf8(&self, index: u16) -> Result<String, Error>
Returns a cloned String at a specified index.
Sourcepub fn get_class_name_opt(&self, index: u16) -> Result<Option<String>, Error>
pub fn get_class_name_opt(&self, index: u16) -> Result<Option<String>, Error>
Returns a class name at a specified index, but if the utf index is 0, None is returned.
Sourcepub fn get_class_name(&self, index: u16) -> Result<String, Error>
pub fn get_class_name(&self, index: u16) -> Result<String, Error>
Returns a class name at a specified index.
Sourcepub fn push_duplicate(&mut self, item: Item) -> Result<u16, Error>
pub fn push_duplicate(&mut self, item: Item) -> Result<u16, Error>
Pushes an item, which might be a duplicate. This removes the possibility of reading a class, which has multiple constant pool entries, which are the same and then accessing the wrong entry.
Sourcepub fn push_utf8(&mut self, content: String) -> Result<u16, Error>
pub fn push_utf8(&mut self, content: String) -> Result<u16, Error>
Pushes a new UTF-8 item on the pool and returns an index to it.
Sourcepub fn push_class(&mut self, name: String) -> Result<u16, Error>
pub fn push_class(&mut self, name: String) -> Result<u16, Error>
Pushes a new class item on the pool and returns an index to it.