implement PLN-0034 internal allocation evidence
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt::Write;
|
||||
use std::sync::atomic::{AtomicU64, Ordering as AtomicOrdering};
|
||||
use std::sync::Arc;
|
||||
|
||||
static STRING_MATERIALIZATION_COUNT: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
/// Opaque handle that references an object stored in the VM heap.
|
||||
///
|
||||
/// This is an index-based handle. It does not imply ownership and carries
|
||||
@@ -76,6 +79,14 @@ impl PartialOrd for Value {
|
||||
}
|
||||
|
||||
impl Value {
|
||||
pub fn string<S>(value: S) -> Self
|
||||
where
|
||||
S: Into<Arc<str>>,
|
||||
{
|
||||
STRING_MATERIALIZATION_COUNT.fetch_add(1, AtomicOrdering::Relaxed);
|
||||
Value::String(value.into())
|
||||
}
|
||||
|
||||
pub fn as_float(&self) -> Option<f64> {
|
||||
match self {
|
||||
Value::Int32(i) => Some(*i as f64),
|
||||
@@ -137,6 +148,10 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn string_materialization_count() -> u64 {
|
||||
STRING_MATERIALIZATION_COUNT.load(AtomicOrdering::Relaxed)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user