Skip to content

Commit 00a1af9

Browse files
committed
Remove Constant::make_name
1 parent b2c9b3c commit 00a1af9

2 files changed

Lines changed: 10 additions & 22 deletions

File tree

bytecode/src/lib.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub trait Constant: Sized {
5353
name: Self::Name,
5454
bag: &Bag,
5555
) -> <Bag::Constant as Constant>::Name {
56-
bag.make_name_ref(name.as_ref())
56+
bag.make_name(name.as_ref())
5757
}
5858
}
5959

@@ -76,19 +76,13 @@ impl Constant for ConstantData {
7676
ConstantData::Ellipsis => Ellipsis,
7777
}
7878
}
79-
fn map_name<Bag: ConstantBag>(name: String, bag: &Bag) -> <Bag::Constant as Constant>::Name {
80-
bag.make_name(name)
81-
}
8279
}
8380

8481
/// A Constant Bag
8582
pub trait ConstantBag: Sized {
8683
type Constant: Constant;
8784
fn make_constant<C: Constant>(&self, constant: BorrowedConstant<C>) -> Self::Constant;
88-
fn make_name(&self, name: String) -> <Self::Constant as Constant>::Name;
89-
fn make_name_ref(&self, name: &str) -> <Self::Constant as Constant>::Name {
90-
self.make_name(name.to_owned())
91-
}
85+
fn make_name(&self, name: &str) -> <Self::Constant as Constant>::Name;
9286
}
9387

9488
#[derive(Clone)]
@@ -99,8 +93,8 @@ impl ConstantBag for BasicBag {
9993
fn make_constant<C: Constant>(&self, constant: BorrowedConstant<C>) -> Self::Constant {
10094
constant.to_owned()
10195
}
102-
fn make_name(&self, name: String) -> <Self::Constant as Constant>::Name {
103-
name
96+
fn make_name(&self, name: &str) -> <Self::Constant as Constant>::Name {
97+
name.to_owned()
10498
}
10599
}
106100

@@ -784,12 +778,8 @@ impl<C: Constant> CodeObject<C> {
784778

785779
/// Same as `map_bag` but clones `self`
786780
pub fn map_clone_bag<Bag: ConstantBag>(&self, bag: &Bag) -> CodeObject<Bag::Constant> {
787-
let map_names = |names: &[C::Name]| {
788-
names
789-
.iter()
790-
.map(|x| bag.make_name_ref(x.as_ref()))
791-
.collect()
792-
};
781+
let map_names =
782+
|names: &[C::Name]| names.iter().map(|x| bag.make_name(x.as_ref())).collect();
793783
CodeObject {
794784
constants: self
795785
.constants
@@ -800,8 +790,8 @@ impl<C: Constant> CodeObject<C> {
800790
varnames: map_names(&self.varnames),
801791
cellvars: map_names(&self.cellvars),
802792
freevars: map_names(&self.freevars),
803-
source_path: bag.make_name_ref(self.source_path.as_ref()),
804-
obj_name: bag.make_name_ref(self.obj_name.as_ref()),
793+
source_path: bag.make_name(self.source_path.as_ref()),
794+
obj_name: bag.make_name(self.obj_name.as_ref()),
805795

806796
instructions: self.instructions.clone(),
807797
locations: self.locations.clone(),

vm/src/builtins/code.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,8 @@ impl ConstantBag for PyObjBag<'_> {
100100
};
101101
PyConstant(obj)
102102
}
103-
fn make_name(&self, name: String) -> PyStrRef {
104-
self.0.intern_string(name).into_pyref()
105-
}
106-
fn make_name_ref(&self, name: &str) -> PyStrRef {
103+
104+
fn make_name(&self, name: &str) -> PyStrRef {
107105
self.0.intern_string(name).into_pyref()
108106
}
109107
}

0 commit comments

Comments
 (0)