FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implement dictionary indexing by trait. by windelbouwman · Pull Request #1187 · RustPython/RustPython · GitHub

Repository navigation

Implement dictionary indexing by trait. - #1187

Merged
coolreader18 merged 2 commits into
masterfrom
dict-keying
Jul 29, 2019
Merged

coolreader18 merged 2 commits into
masterfrom
dict-keying

Conversation

windelbouwman commented Jul 28, 2019 •
edited
Loading

Copy link
Copy Markdown
Contributor

This add support for indexing the dictionary by string. So instead of creating a PyStringRef, we now can use rust's String type to index a dict.

Comment thread vm/src/dictdatatype.rs

/// Implement trait for the str type, so that we can use strings
/// to index dictionaries.
impl DictKey for String {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
impl DictKey for String {
impl DictKey for str {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I tried this, without success. I get this compilation error:

 --> vm/src/dictdatatype.rs:363:24
    |
363 |         let val = dict.get(&vm, "x").unwrap().unwrap();
    |                        ^^^ doesn't have a size known at compile-time

coolreader18 Jul 28, 2019 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Oh, I think it's because it's trying to make a double-fat pointer, with both a vtable and a slice length, and it doesn't like that.

Comment thread vm/src/dictdatatype.rs Outdated
fn do_eq(&self, vm: &VirtualMachine, other_key: &PyObjectRef) -> PyResult<bool> {
// Fall back to PyString implementation.
let s = vm.new_str(self.to_string());
s.do_eq(vm, other_key)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I feel like we could have a more efficient eq implementation here than reallocating the string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Absolutely, this involves checking the specific python type to be of PyStringRef, and then doing a string compare. I suspect this happens only in a couple of cases, after the first hash compare is a success. I will implement this though, since I think it is a good idea.

coolreader18 merged commit c8ce3bd into master Jul 29, 2019
windelbouwman deleted the dict-keying branch September 1, 2019 09:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL