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

Avoid copying string for WKT parsing #220

Merged
merged 1 commit into from
Jul 25, 2024

Conversation

kylebarron
Copy link
Member

@kylebarron kylebarron commented Jul 17, 2024

Currently bytes are converted into a Read and then collected back into a string. It would be preferable to pass [u8] or str directly into wkt::Wkt::from_str

@@ -11,7 +12,10 @@ pub struct Wkt<B: AsRef<[u8]>>(pub B);

impl<B: AsRef<[u8]>> GeozeroGeometry for Wkt<B> {
fn process_geom<P: GeomProcessor>(&self, processor: &mut P) -> Result<()> {
read_wkt(&mut self.0.as_ref(), processor)
let wkt_str = std::str::from_utf8(self.0.as_ref())
Copy link
Member Author

Choose a reason for hiding this comment

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

I know we've been changing the API repeatedly lately, but it would be nice here if the user could declare they already have UTF8 data. I.e. maybe WktStr<S> where S: AsRef<str> separated from Wkt<B> where B: AsRef<[u8]>

Copy link
Member

Choose a reason for hiding this comment

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

I know we've been changing the API repeatedly lately, but it would be nice here if the user could declare they already have UTF8 data

To make sure I understand, you're proposing that, we remove the WktStr deprecation and make it generic? Sounds reasonable, just making sure I understand.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I believe so. Just so that the buffers don't have to be checked again via std::str::from_utf8

@michaelkirk michaelkirk added this pull request to the merge queue Jul 25, 2024
Merged via the queue into georust:main with commit c8a5f91 Jul 25, 2024
1 check passed
@kylebarron kylebarron deleted the kyle/avoid-str-copy branch July 25, 2024 21:09
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