Skip to content

Small int cache like CPython #1502

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

Merged
merged 2 commits into from
Oct 10, 2019

Conversation

youknowone
Copy link
Member

No description provided.

pub fn new_int<T: Into<BigInt>>(&self, i: T) -> PyObjectRef {
let i = i.into();
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking that instead of immediately converting it, T could be Into<BigInt> + PartialOrd<i32>, to save on the overhead of allocation for a BigInt.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because PartialOrd<i32> is not implemented for unsigned ints, this way will be tricky

Copy link
Member

Choose a reason for hiding this comment

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

Maybe T could be ToPrimitive?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is great idea. I was struggling with TryInto and TryFrom but ToPrimitive is a lot easier to do this. Thanks!

@coolreader18 coolreader18 merged commit 8bce893 into RustPython:master Oct 10, 2019
@youknowone youknowone deleted the small-int-cache branch October 10, 2019 15:57
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.

2 participants