-
Notifications
You must be signed in to change notification settings - Fork 3
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
Migrate to phf
, add no-std
support
#9
Conversation
Are you trying to rewrite |
161eb9e
to
470c35c
Compare
I rebased on latest master and applied your early suggestions. I pushed it commit by commit to have CI runs for each one of them. Would you like me to split this PR up or are you okay with keeping it this big? |
I just found, that you can actually use a different name for the build script: It's up to you to decide, though. :) |
build.rs
Outdated
struct CodeTables { | ||
created: String, | ||
tables: Vec<(u16, Table)>, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want a doc comment that shows this is parsed content of code_tables.json
. This is just an draft.
/// Parsed code tables from `code_tables.json`
struct CodeTables {
/// ISO 8601 Timestamp when tables in the JSON are created
created: String,
//// code tables main part
////
//// `([code page], [table definition])`
tables: Vec<(u16, Table)>,
}
The name ParsedCodeTablesJsonContent
might be better because this is not tables itself and has also a timestamp.
Also could you tell me why you think the Vec
of the tuple is better than a map (Map
, HashMap
, or something similar)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I called it CodeTables
, because the file is called code_tables.json
. I also wanted to avoid a long name.
I chose Vec
, because I want the tables to be sorted and stable in the generated output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkroening Autocompletion by modern editors reduces a pain of typing long names a lot, though.
because I want the tables to be sorted and stable in the generated output.
Why not BTreeMap
? Also you want to clarify a sort is needed in a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was more concerned about reading, but if you want, I can rename it to ParsedCodeTablesJsonContent
.
I chose Vec
, because it is faster and simpler if we only sort it once and don't mutate it. BTreeMap
would also work fine though and I can migrate to it if you want me to. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkroening I'm glad to hear your opinion. You don't have to modify.
I chose Vec, because it is faster
BTreeMap
has the same order Vec
, but I didn't know the combination of Vec
and sort
is faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should scale the same, and BTreeMap
makes sure that the collection is kept sorted. Vec
provides better cache locality, since its items are stored in a row. So it's about nice access patterns when iterating. For the BTreeMap
, we'd jump around in memory a lot.
All of this is super irrelevant for our use case, since this is not at all performance sensitive, and benchmarks might prove me wrong in this case. So my choice was rather arbitrary and mainly out of habit. :)
@mkroening I see, and you can go ahead (you can stick to |
Enable Rust 2021 We need the version 2 feature resolver for no_std support. Otherwise, `phf_codegen` in `build-dependencies` enables the `std` feature for `phf_shared` in the normal `dependencies` scope as well. https://doc.rust-lang.org/cargo/reference/features.html#feature-resolver-version-2
Sorry for taking so long. I addressed your concerns. :) |
- Use `phf` (perfect hash map) instead of `ahash` (#7, #9) by @mkroening - Actual type of `OEMCPHashMap` will be changed. I suppose that you do not have to modify your code; recompile might be needed (I do not know much) - (Use `clippy` as lints (#8) by @mkroening) - Remove unused dependency on `hfs_nfd`
This change is now available in 1.2.0. Sorry to keep you waiting for a long time. |
No worries! Thanks a lot! :) |
- Use phf (perfect hash map) instead of ahash (#7, #9) by @mkroening Actual type of OEMCPHashMap will be changed.
Sorry I'd like you to use 2.0.0(-beta.1) instead. I found this patch is a breaking change, contrary to my expectations. |
- Use `once_cell` instead of `lazy_static` for test - Comply with Clippy rules - More small fixes The following changes has been included since 2.0.0-beta.1. - Use phf (perfect hash map) instead of ahash (#7, #9) by @mkroening Actual type of OEMCPHashMap will be changed.
Closes #7.
This PR is structured as follows:
Migrate code generation from
generate_table.py
tobuild.rs
.Before,
generate_table.py
was called once and the generated code was then committed to the repository.Now,
build.rs
generates the code fromassets/code_tables.json
on the fly for every user before the compilation. The resulting code is not saved persistently anywhere, and is regenerated aftercargo clean
.This step does not change the generated code or any dependencies.
Migrate to
phf
.This change migrates the code generation for hash maps from the manual
lazy_static
andahash::AHashMap
based code to aphf_codegen
andphf::Map
based one.This commit and the following ones are for supporting
no-std
environments:Enable Rust 2021 to enable Cargo resolver version 2.
Without this,
phf_codegen
inbuild-dependencies
enables thestd
feature for
phf_shared
in the normaldependencies
scope as well.See https://doc.rust-lang.org/cargo/reference/features.html#feature-resolver-version-2
The next two commits are for refactoring all functionality that requires an allocator into one module for easier gating.
Move string functions into string module.
Move
TableType
string methods to string module.Add
no_std
support.This makes all functionality depend on the
alloc
crate instead ofstd
, making it suitable forno-std
environments.Additionally, the
alloc
functionality can be disabled via Cargo features forno-std
environments withoutalloc
.