Skip to content

Commit abe60a7

Browse files
author
Michael Spector
committed
Expose Regex memory usage info (fixes rust-lang#943)
1 parent 66a3bca commit abe60a7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/regex/bytes.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,15 @@ impl Regex {
14291429
pub fn locations(&self) -> CaptureLocations {
14301430
self.capture_locations()
14311431
}
1432+
1433+
/// Returns the memory usage, in bytes, of this `Regex`.
1434+
///
1435+
/// This does **not** include the stack size used up by this `Regex`.
1436+
/// To compute that, use `std::mem::size_of::<Regex>()`.
1437+
#[inline]
1438+
pub fn memory_usage(&self) -> usize {
1439+
self.meta.memory_usage()
1440+
}
14321441
}
14331442

14341443
/// Represents a single match of a regex in a haystack.

src/regex/string.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,15 @@ impl Regex {
14321432
pub fn locations(&self) -> CaptureLocations {
14331433
self.capture_locations()
14341434
}
1435+
1436+
/// Returns the memory usage, in bytes, of this `Regex`.
1437+
///
1438+
/// This does **not** include the stack size used up by this `Regex`.
1439+
/// To compute that, use `std::mem::size_of::<Regex>()`.
1440+
#[inline]
1441+
pub fn memory_usage(&self) -> usize {
1442+
self.meta.memory_usage()
1443+
}
14351444
}
14361445

14371446
/// Represents a single match of a regex in a haystack.

0 commit comments

Comments
 (0)