Skip to content

Commit 6208ac7

Browse files
committed
fixup! Generate actions HashMap at ValidatorSchema instantiation
1 parent a5865a4 commit 6208ac7

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

cedar-policy-validator/src/coreschema.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,21 @@ use cedar_policy_core::extensions::{ExtensionFunctionLookupError, Extensions};
1919
use cedar_policy_core::{ast, entities};
2020
use miette::Diagnostic;
2121
use smol_str::SmolStr;
22-
use std::collections::{HashMap, HashSet};
22+
use std::collections::HashSet;
2323
use std::sync::Arc;
2424
use thiserror::Error;
2525

2626
/// Struct which carries enough information that it can (efficiently) impl Core's `Schema`
2727
#[derive(Debug)]
2828
pub struct CoreSchema<'a> {
2929
/// Contains all the information
30-
schema: &'a ValidatorSchema,
31-
/// For easy lookup, this is a map from action name to `Entity` object
32-
/// for each action in the schema. This information is contained in the
33-
/// `ValidatorSchema`, but not efficient to extract -- getting the `Entity`
34-
/// from the `ValidatorSchema` is O(N) as of this writing, but with this
35-
/// cache it's O(1).
36-
actions: HashMap<ast::EntityUID, Arc<ast::Entity>>,
30+
schema: &'a ValidatorSchema
3731
}
3832

3933
impl<'a> CoreSchema<'a> {
4034
/// Create a new `CoreSchema` for the given `ValidatorSchema`
4135
pub fn new(schema: &'a ValidatorSchema) -> Self {
4236
Self {
43-
actions: schema.actions.clone(),
4437
schema,
4538
}
4639
}
@@ -55,7 +48,7 @@ impl<'a> entities::Schema for CoreSchema<'a> {
5548
}
5649

5750
fn action(&self, action: &ast::EntityUID) -> Option<Arc<ast::Entity>> {
58-
self.actions.get(action).cloned()
51+
self.schema.actions.get(action).cloned()
5952
}
6053

6154
fn entity_types_with_basename<'b>(
@@ -76,7 +69,7 @@ impl<'a> entities::Schema for CoreSchema<'a> {
7669
}
7770

7871
fn action_entities(&self) -> Self::ActionEntityIterator {
79-
self.actions.values().map(Arc::clone).collect()
72+
self.schema.actions.values().map(Arc::clone).collect()
8073
}
8174
}
8275

cedar-policy-validator/src/schema.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,7 @@ impl ValidatorSchema {
858858
Entities::from_entities(
859859
self.actions
860860
.values()
861-
.map(|entity| entity.as_ref().clone())
862-
.collect::<Vec<Entity>>(),
861+
.map(|entity| entity.as_ref().clone()),
863862
None::<&cedar_policy_core::entities::NoEntitiesSchema>, // we don't want to tell `Entities::from_entities()` to add the schema's action entities, that would infinitely recurse
864863
TCComputation::AssumeAlreadyComputed,
865864
extensions,

0 commit comments

Comments
 (0)