Skip to content

Commit

Permalink
Inline some trivial functions
Browse files Browse the repository at this point in the history
Reviewed By: JakobDegen

Differential Revision: D63615330

fbshipit-source-id: 2fcb176a69b65cc70a49d3f8cd4c1d8108dd56e6
  • Loading branch information
stepancheg authored and facebook-github-bot committed Sep 30, 2024
1 parent 27cfe1d commit 868b5f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
25 changes: 7 additions & 18 deletions starlark-rust/starlark/src/eval/runtime/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,6 @@ impl<'a, 'v, S: ArgSymbol> ArgNames<'a, 'v, S> {
pub(crate) fn names(&self) -> &'a [(S, StringValue<'v>)] {
self.names
}

pub(crate) fn iter(&self) -> impl ExactSizeIterator<Item = &'a (S, StringValue<'v>)> {
self.names.iter()
}

pub(crate) fn is_empty(&self) -> bool {
self.names.is_empty()
}

pub(crate) fn len(&self) -> usize {
self.names.len()
}
}

/// Either full arguments, or short arguments for positional-only calls.
Expand Down Expand Up @@ -274,8 +262,8 @@ impl<'v, 'a> Arguments<'v, 'a> {
pub fn names_map(&self) -> crate::Result<SmallMap<StringValue<'v>, Value<'v>>> {
match self.unpack_kwargs()? {
None => {
let mut result = SmallMap::with_capacity(self.0.names.len());
for (k, v) in self.0.names.iter().zip(self.0.named) {
let mut result = SmallMap::with_capacity(self.0.names.names().len());
for (k, v) in self.0.names.names().iter().zip(self.0.named) {
let old =
result.insert_hashed(Hashed::new_unchecked(k.0.small_hash(), k.1), *v);
if unlikely(old.is_some()) {
Expand All @@ -288,15 +276,16 @@ impl<'v, 'a> Arguments<'v, 'a> {
Ok(result)
}
Some(kwargs) => {
if self.0.names.is_empty() {
if self.0.names().names().is_empty() {
match kwargs.downcast_ref_key_string() {
Some(kwargs) => Ok(kwargs.clone()),
None => Err(FunctionError::ArgsValueIsNotString.into()),
}
} else {
// We have to insert the names before the kwargs since the iteration order is observable
let mut result = SmallMap::with_capacity(self.0.names.len() + kwargs.len());
for (k, v) in self.0.names.iter().zip(self.0.named) {
let mut result =
SmallMap::with_capacity(self.0.names.names().len() + kwargs.len());
for (k, v) in self.0.names.names().iter().zip(self.0.named) {
let old =
result.insert_hashed(Hashed::new_unchecked(k.0.small_hash(), k.1), *v);
if unlikely(old.is_some()) {
Expand Down Expand Up @@ -402,7 +391,7 @@ impl<'v, 'a> Arguments<'v, 'a> {
fn bad(x: &Arguments) -> crate::Result<()> {
// We might have a empty kwargs dictionary, but probably have an error
let mut extra = Vec::new();
extra.extend(x.0.names.iter().map(|x| x.0.as_str().to_owned()));
extra.extend(x.0.names.names().iter().map(|x| x.0.as_str().to_owned()));
if let Some(kwargs) = x.unpack_kwargs()? {
for k in kwargs.keys() {
extra.push(Arguments::unpack_kwargs_key(k)?.to_owned());
Expand Down
4 changes: 2 additions & 2 deletions starlark-rust/starlark/src/eval/runtime/params/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,8 @@ impl<'v> ParametersSpec<Value<'v>> {
// So no duplicate checking until after all positional arguments
let mut lowest_name = usize::MAX;
// Avoid a lot of loop setup etc in the common case
if !args.names().is_empty() {
for ((name, name_value), v) in args.names().iter().zip(args.named()) {
if !args.names().names().is_empty() {
for ((name, name_value), v) in args.names().names().iter().zip(args.named()) {
// Safe to use new_unchecked because hash for the Value and str are the same
match name.get_index_from_param_spec(self) {
None => {
Expand Down

0 comments on commit 868b5f8

Please sign in to comment.