Skip to content

Commit

Permalink
Use compact_rc (microsoft#139)
Browse files Browse the repository at this point in the history
There is not much use for weak_counts in Rc for us.

Signed-off-by: Anand Krishnamoorthi <[email protected]>
  • Loading branch information
anakrish authored Feb 10, 2024
1 parent 5044d54 commit a381c38
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions src/builtins/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions src/builtins/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
4 changes: 3 additions & 1 deletion src/builtins/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 1 addition & 2 deletions src/builtins/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
3 changes: 1 addition & 2 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SourceStr, Value>;
Expand Down Expand Up @@ -61,7 +60,7 @@ pub struct Interpreter {
active_rules: Vec<Ref<Rule>>,
builtins_cache: BTreeMap<(&'static str, Vec<Value>), Value>,
no_rules_lookup: bool,
traces: Option<Vec<std::rc::Rc<str>>>,
traces: Option<Vec<Rc<str>>>,
allow_deprecated: bool,
strict_builtin_errors: bool,
imports: BTreeMap<String, Ref<Expr>>,
Expand Down
3 changes: 2 additions & 1 deletion src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ 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};
use serde::de::{self, Deserializer, MapAccess, SeqAccess, Visitor};
use serde::ser::{SerializeMap, Serializer};
use serde::{Deserialize, Serialize};

pub type Rc<T> = compact_rc::Rc16<T>;

/// A value in a Rego document.
///
/// Value is similar to a [`serde_json::value::Value`], but has the following additional
Expand Down

0 comments on commit a381c38

Please sign in to comment.