Skip to content

Conversation

@coolreader18
Copy link
Member

Yeah, not all that big of an optimization, but it seemed dumb to be allocating a new Rc for something that's essentially empty.

@coolreader18 coolreader18 force-pushed the coolreader18/empty-tuple branch from 9f3a26e to dfa66b0 Compare July 25, 2019 06:35
@windelbouwman
Copy link
Contributor

Hmm, this is interesting, and I would rather not do this. But actually this solves this example:

>>> a = ()
>>> b = ()
>>> a is b
True

Please add a test snippet for this special case.

src/main.rs Outdated
fn run_module(vm: &VirtualMachine, module: &str) -> PyResult<()> {
debug!("Running module {}", module);
vm.import(module, &vm.ctx.new_tuple(vec![]), 0)?;
vm.import(module, &vm.ctx.empty_tuple(), 0)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not use this empty tuple directly, and make it a private method on PyContext. I think it is better to call the new_tuple function with an empty vector, so we have one way to create a tuple.

self.not_implemented.clone().into_object()
}

pub fn empty_tuple(&self) -> PyObjectRef {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method could be private, or merged into the new_tuple function.

@coolreader18 coolreader18 force-pushed the coolreader18/empty-tuple branch from dfa66b0 to 8aee745 Compare July 25, 2019 14:28
@windelbouwman windelbouwman merged commit c998549 into master Jul 25, 2019
@coolreader18 coolreader18 deleted the coolreader18/empty-tuple branch August 2, 2019 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants