Skip to content

Commit

Permalink
Expose Regex memory usage info (fixes rust-lang#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Spector committed Apr 5, 2024
1 parent 66a3bca commit abe60a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/regex/bytes.rs
Expand Up @@ -1429,6 +1429,15 @@ impl Regex {
pub fn locations(&self) -> CaptureLocations {
self.capture_locations()
}

/// Returns the memory usage, in bytes, of this `Regex`.
///
/// This does **not** include the stack size used up by this `Regex`.
/// To compute that, use `std::mem::size_of::<Regex>()`.
#[inline]
pub fn memory_usage(&self) -> usize {
self.meta.memory_usage()
}
}

/// Represents a single match of a regex in a haystack.
Expand Down
9 changes: 9 additions & 0 deletions src/regex/string.rs
Expand Up @@ -1432,6 +1432,15 @@ impl Regex {
pub fn locations(&self) -> CaptureLocations {
self.capture_locations()
}

/// Returns the memory usage, in bytes, of this `Regex`.
///
/// This does **not** include the stack size used up by this `Regex`.
/// To compute that, use `std::mem::size_of::<Regex>()`.
#[inline]
pub fn memory_usage(&self) -> usize {
self.meta.memory_usage()
}
}

/// Represents a single match of a regex in a haystack.
Expand Down

0 comments on commit abe60a7

Please sign in to comment.