From a381c38a90ef0ddff15dc1e380035367460e4547 Mon Sep 17 00:00:00 2001 From: Anand Krishnamoorthi <35780660+anakrish@users.noreply.github.com> Date: Fri, 9 Feb 2024 23:22:09 -0800 Subject: [PATCH] Use compact_rc (#139) There is not much use for weak_counts in Rc for us. Signed-off-by: Anand Krishnamoorthi --- Cargo.toml | 1 + src/builtins/arrays.rs | 3 +-- src/builtins/objects.rs | 3 +-- src/builtins/strings.rs | 4 +++- src/builtins/utils.rs | 3 +-- src/interpreter.rs | 3 +-- src/value.rs | 3 ++- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7b3a7c86..894e5759 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,6 +90,7 @@ uuid = { version = "1.6.1", features = ["v4", "fast-rng"], optional = true } jsonschema = { version = "0.17.1", default-features = false, optional = true } chrono = { version = "0.4.31", optional = true } chrono-tz = { version = "0.8.5", optional = true } +compact-rc = "0.5.2" [dev-dependencies] diff --git a/src/builtins/arrays.rs b/src/builtins/arrays.rs index 13757874..e1dea3ca 100644 --- a/src/builtins/arrays.rs +++ b/src/builtins/arrays.rs @@ -5,12 +5,11 @@ use crate::ast::{Expr, Ref}; use crate::builtins; use crate::builtins::utils::{ensure_args_count, ensure_array, ensure_numeric}; use crate::lexer::Span; -use crate::value::Value; +use crate::value::{Rc, Value}; use std::collections::HashMap; use anyhow::Result; -use std::rc::Rc; pub fn register(m: &mut HashMap<&'static str, builtins::BuiltinFcn>) { m.insert("array.concat", (concat, 2)); diff --git a/src/builtins/objects.rs b/src/builtins/objects.rs index 8cf8053e..3e942862 100644 --- a/src/builtins/objects.rs +++ b/src/builtins/objects.rs @@ -5,11 +5,10 @@ use crate::ast::{Expr, Ref}; use crate::builtins; use crate::builtins::utils::{ensure_args_count, ensure_array, ensure_object}; use crate::lexer::Span; -use crate::value::Value; +use crate::value::{Rc, Value}; use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::iter::Iterator; -use std::rc::Rc; use anyhow::{bail, Result}; diff --git a/src/builtins/strings.rs b/src/builtins/strings.rs index c83ceb8a..286adf18 100644 --- a/src/builtins/strings.rs +++ b/src/builtins/strings.rs @@ -157,7 +157,9 @@ fn to_string(v: &Value, unescape: bool) -> String { match v { Value::Null => "null".to_owned(), Value::Bool(b) => b.to_string(), - Value::String(s) if unescape => serde_json::to_string(&s).unwrap_or(s.as_ref().to_string()), + Value::String(s) if unescape => { + serde_json::to_string(s.as_ref()).unwrap_or(s.as_ref().to_string()) + } Value::String(s) => s.as_ref().to_string(), Value::Number(n) => n.format_decimal(), Value::Array(a) => { diff --git a/src/builtins/utils.rs b/src/builtins/utils.rs index ec0696c7..a1200a52 100644 --- a/src/builtins/utils.rs +++ b/src/builtins/utils.rs @@ -4,10 +4,9 @@ use crate::ast::{Expr, Ref}; use crate::lexer::Span; use crate::number::Number; -use crate::value::Value; +use crate::value::{Rc, Value}; use std::collections::{BTreeMap, BTreeSet}; -use std::rc::Rc; use anyhow::{bail, Result}; diff --git a/src/interpreter.rs b/src/interpreter.rs index f23aa3dd..c5e088d9 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -16,7 +16,6 @@ use log::info; use std::collections::btree_map::Entry as BTreeMapEntry; use std::collections::{hash_map::Entry, BTreeMap, BTreeSet, HashMap}; use std::ops::Bound::*; -use std::rc::Rc; use std::str::FromStr; type Scope = BTreeMap; @@ -61,7 +60,7 @@ pub struct Interpreter { active_rules: Vec>, builtins_cache: BTreeMap<(&'static str, Vec), Value>, no_rules_lookup: bool, - traces: Option>>, + traces: Option>>, allow_deprecated: bool, strict_builtin_errors: bool, imports: BTreeMap>, diff --git a/src/value.rs b/src/value.rs index 250365dd..f6ccb7e8 100644 --- a/src/value.rs +++ b/src/value.rs @@ -8,7 +8,6 @@ use std::collections::{BTreeMap, BTreeSet}; use std::convert::AsRef; use std::ops; use std::path::Path; -use std::rc::Rc; use std::str::FromStr; use anyhow::{anyhow, bail, Result}; @@ -16,6 +15,8 @@ use serde::de::{self, Deserializer, MapAccess, SeqAccess, Visitor}; use serde::ser::{SerializeMap, Serializer}; use serde::{Deserialize, Serialize}; +pub type Rc = compact_rc::Rc16; + /// A value in a Rego document. /// /// Value is similar to a [`serde_json::value::Value`], but has the following additional