Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Replace Contains Key with Entry #4483

Open
wants to merge 20 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
33a9aa8
feat: replace `.contains_key()` with `.entry()` where possible
ASuciuX Mar 4, 2024
6fc8d67
feat: fix formatting errors from `cargo fmt`
ASuciuX Mar 4, 2024
e4b2f8a
feat: uncomment jemalloc
ASuciuX Mar 4, 2024
86cf2a1
replace contains_key in immutable data with raw_entry
ASuciuX Mar 4, 2024
4d8b2f1
removed `raw_entry().from_key(name)` in favor of `contains_key` for b…
ASuciuX Mar 5, 2024
e9d625d
update format
ASuciuX Mar 5, 2024
885b6e5
Merge branch 'next' into chore/replace-contains-key-with-entry
ASuciuX Mar 5, 2024
a8597f1
feat: replace inserts on maps with inserts on entries
ASuciuX Mar 8, 2024
3352be9
feat: code optimizations
ASuciuX Mar 10, 2024
2f14dbd
feat: small code optimization
ASuciuX Mar 11, 2024
a2f924a
feat: remove entry API from all crates besides 'clarity'
ASuciuX Mar 15, 2024
bc2e4c5
feat: remove unused entry import
ASuciuX Mar 15, 2024
c6a0f9f
Merge branch 'next' into chore/replace-contains-key-with-entry
ASuciuX Mar 15, 2024
af75e54
Merge branch 'next' into chore/replace-contains-key-with-entry
jbencin Mar 20, 2024
7434810
Merge branch 'next' into chore/replace-contains-key-with-entry
jbencin Mar 20, 2024
0d914b3
Merge branch 'next' into chore/replace-contains-key-with-entry
jbencin Mar 21, 2024
ab87986
feat: remove `.collect()` from trait definition iter
ASuciuX Mar 22, 2024
283f46b
Merge branch 'next' into chore/replace-contains-key-with-entry
ASuciuX Mar 22, 2024
9055eb0
Merge branch 'next' into chore/replace-contains-key-with-entry
ASuciuX Apr 12, 2024
6526182
add entry trait implementation for readability
ASuciuX Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
removed raw_entry().from_key(name) in favor of contains_key for b…
…etter benchmark results
  • Loading branch information
ASuciuX committed Mar 5, 2024
commit 4d8b2f14800cc1ee8759aaabf4292e8de3437d1c
14 changes: 7 additions & 7 deletions clarity/src/vm/analysis/type_checker/v2_05/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ impl ContractContext {
}

pub fn check_name_used(&self, name: &str) -> CheckResult<()> {
if self.variable_types.raw_entry().from_key(name).is_some()
|| self.persisted_variable_types.raw_entry().from_key(name).is_some()
|| self.private_function_types.raw_entry().from_key(name).is_some()
|| self.public_function_types.raw_entry().from_key(name).is_some()
if self.variable_types.contains_key(name)
|| self.persisted_variable_types.contains_key(name)
|| self.private_function_types.contains_key(name)
|| self.public_function_types.contains_key(name)
|| self.fungible_tokens.contains(name)
|| self.non_fungible_tokens.raw_entry().from_key(name).is_some()
|| self.traits.raw_entry().from_key(name).is_some()
|| self.map_types.raw_entry().from_key(name).is_some()
|| self.non_fungible_tokens.contains_key(name)
|| self.traits.contains_key(name)
|| self.map_types.contains_key(name)
{
Err(CheckError::new(CheckErrors::NameAlreadyUsed(
name.to_string(),
Expand Down
14 changes: 7 additions & 7 deletions clarity/src/vm/analysis/type_checker/v2_1/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl TraitContext {

pub fn is_name_used(&self, name: &str) -> bool {
match self {
Self::Clarity1(map) => map.raw_entry().from_key(name).is_some(),
Self::Clarity1(map) => map.contains_key(name),
Self::Clarity2 { defined, all: _ } => defined.contains(name),
}
}
Expand Down Expand Up @@ -168,14 +168,14 @@ impl ContractContext {
}

pub fn check_name_used(&self, name: &str) -> CheckResult<()> {
if self.variable_types.raw_entry().from_key(name).is_some()
|| self.persisted_variable_types.raw_entry().from_key(name).is_some()
|| self.private_function_types.raw_entry().from_key(name).is_some()
|| self.public_function_types.raw_entry().from_key(name).is_some()
if self.variable_types.contains_key(name)
|| self.persisted_variable_types.contains_key(name)
|| self.private_function_types.contains_key(name)
|| self.public_function_types.contains_key(name)
|| self.fungible_tokens.contains(name)
|| self.non_fungible_tokens.raw_entry().from_key(name).is_some()
|| self.non_fungible_tokens.contains_key(name)
|| self.traits.is_name_used(name)
|| self.map_types.raw_entry().from_key(name).is_some()
|| self.map_types.contains_key(name)
{
Err(CheckError::new(CheckErrors::NameAlreadyUsed(
name.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ mod test {

for expr in ast.iter() {
depth_traverse::<_, _, ()>(expr, |x| {
assert!(!visited.raw_entry().from_key(&x.id).is_some());
assert!(!visited.contains_key(&x.id));
visited.insert(x.id, true);
Ok(())
})
Expand Down
6 changes: 3 additions & 3 deletions clarity/src/vm/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1825,10 +1825,10 @@ impl ContractContext {

pub fn is_name_used(&self, name: &str) -> bool {
is_reserved(name, self.get_clarity_version())
|| self.variables.raw_entry().from_key(name).is_some()
|| self.functions.raw_entry().from_key(name).is_some()
|| self.variables.contains_key(name)
|| self.functions.contains_key(name)
|| self.persisted_names.contains(name)
|| self.defined_traits.raw_entry().from_key(name).is_some()
|| self.defined_traits.contains_key(name)
}

pub fn get_clarity_version(&self) -> &ClarityVersion {
Expand Down