Skip to content
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

Data provider: match on TinyStr instead of &str #212

Closed
sffc opened this issue Aug 21, 2020 · 4 comments · Fixed by #361
Closed

Data provider: match on TinyStr instead of &str #212

sffc opened this issue Aug 21, 2020 · 4 comments · Fixed by #361
Assignees
Labels
A-performance Area: Performance (CPU, Memory) C-data-infra Component: provider, datagen, fallback, adapters T-enhancement Type: Nice-to-have but not required

Comments

@sffc
Copy link
Member

sffc commented Aug 21, 2020

We can be more efficient by matching on TinyStr by integer value rather than &str.

Blocked on zbraniecki/tinystr#17

CC @zbraniecki

@sffc sffc added T-enhancement Type: Nice-to-have but not required A-performance Area: Performance (CPU, Memory) C-data-infra Component: provider, datagen, fallback, adapters labels Aug 21, 2020
@zbraniecki
Copy link
Member

Unblocked! :) https://crates.io/crates/tinystr

@sffc
Copy link
Member Author

sffc commented Aug 23, 2020

I got the following to work on nightly:

        const CARDINAL: TinyStr16 = tinystr16!("cardinal");
        const ORDINAL: TinyStr16 = tinystr16!("ordinal");
        match data_key.sub_category {
            CARDINAL => self.cardinal_rules.as_ref(),
            ORDINAL => self.ordinal_rules.as_ref(),
            _ => return Err(data_key.into()),
        }

It doesn't work on stable. If I try, it says:

error[E0658]: procedural macros cannot be expanded to expressions
  --> components/cldr-json-data-provider/src/transform/plurals.rs:80:36
   |
80 |         const ORDINAL: TinyStr16 = tinystr16!("ordinal");
   |                                    ^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information

error: aborting due to 3 previous errors

@sffc
Copy link
Member Author

sffc commented Aug 23, 2020

Also see zbraniecki/tinystr#22

@sffc sffc self-assigned this Aug 27, 2020
@sffc
Copy link
Member Author

sffc commented Aug 28, 2020

The code from #212 (comment) works now in rustc 1.46.0 (04488afe3 2020-08-24).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-performance Area: Performance (CPU, Memory) C-data-infra Component: provider, datagen, fallback, adapters T-enhancement Type: Nice-to-have but not required
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants