Improve ergonomics - rebuild Reader around native utf-8 string types - #963
Improve ergonomics - rebuild Reader around native utf-8 string types#963dralley wants to merge 21 commits into
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #963 +/- ##
==========================================
- Coverage 57.31% 55.82% -1.50%
==========================================
Files 46 47 +1
Lines 18197 18303 +106
==========================================
- Hits 10429 10217 -212
- Misses 7768 8086 +318
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| Cow::Owned(owned) => CowRef::Owned(owned), | ||
| }, | ||
| Cow::Borrowed(b) => { | ||
| let name_str = std::str::from_utf8(&b[..start.name_len]) |
There was a problem hiding this comment.
There will be a handful of these temporary from_utf8() calls, but they should be able to be removed by by subsequent commits as additional types are switched over.
e028123 to
4a01f13
Compare
|
@Mingun Would you be satisfied if edit: well, that's what I implemented. Sidenote: maybe |
|
These 3 particular commits are ready for review, with the caveat that there will be (probably) 6-8 additional commits coming. |
a198941 to
27e09f5
Compare
5474a71 to
266bf6f
Compare
|
Remaining design questions, not all of which actually need to be dealt with in this PR:
|
|
Also, I can improve the commit messages and Changelog entries if needed. The initial are pretty... concise. |
4ba0d68 to
cd8da9b
Compare
|
First, I would prefer to keep the ability to parse non-utf8 encoded documents without recoding. XML itself can be parsed without knowing the exact encoding, it is enough if it is XML-compatible (which is all legacy 1-byte encodings that we support). So, is it possible to create a separate reader and event which will be always UTF-8 encoded and keep the current ones for advanced usage? It is fine to promote the new UTF-8-based reader as default, but keep the ability to work with non-UTF-8 input without recoding. Here is the same situation as for regexp -- although it is defined in terms of strings, nothing prevents it from running on top of any byte arrays. The author of regexp engine even created a |
IMO, it is not worth the ergonomic and maintenance costs. If you look at all the major XML parsing libraries like e.g. libxml2 parses & handles UTF-8 only, performs a streaming decode of other encodings expat selects either UTF-8 or UTF-16 as an internal encoding at compile time, decodes to that, returns whichever type of string was selected encoding/xml is the same as libxml2 - utf-8 only Decoding is very very fast relative to XML parsing - it varies depending on encoding and the precise makeup of the document of course, but generally between 15 and 90 Gbps, whereas XML parsing is currently in the ballpark of 0.5 Gbps and often slower, so I don't really think that's a reason to avoid it either. I would maybe accept the argument that it's a huge API change and it might be warranted to support both for some time to allow a migration, but even then it would likely be easier to just maintain an older branch for a longer period of time. Duplicating the reader would, I think, be way way more work than it's worth. |
|
Also, the reason the XML libraries work that way, apart from overall simplicity, is that the XML standard effectively requires working that way. The standard actually said that all XML processors should be able to handle I'm not a complete stickler for compliance, and we do provide a handful of features catering to noncompliant XML and XML-derived document formats (which is fine), but in this case I really don't see a good reason to go out of our way to break with it. It's just more complexity for a use case of (IMO) very questionable value. Section 2.2
Section 4.3.3 - Character Encoding in Entities
...
|
|
I rebased anyway, but all the changes are in new commits, everything after and including 22c4a94 "Make DeError::UnexpectedStart carry String" |
|
@Mingun Is this still considered blocked? And on what, specifically? |
|
I merge this in 3 days without further comment |
Document that Reader expects UTF-8 input.
Required for const fn split_at - needed to keep trim_xml* functions const.
Make xml*_content() methods infalliable as they no longer handle decoding.
Deprecate decode_and* methods, since they no longer serve a purpose.
It is now impossible for ReaderState to receive unvalidated bytes. This avoids some redundant validation and allows making different decisions about how to validate for different types of XmlSource.
Eliminates some duplicitous validation
Custom impl no longer required after converting to String-based types.
BytesStart / BytesPI::attributes_raw() ought to return &str BytesStart::try_get_attribute() ought to take &str - drop the AsRef also.
It's a little cleaner, makes no practical difference otherwise.
Possible now that the MSRV is bumped to 1.86
|
Unfortunately, I have not yet been able to find time to think about alternative solutions. I don't know when it will be. So that your enthusiasm does not fade, I will not obstruct merging this PR, but only a request - if #982 is completed in the near future, merge it first and make release with it, and then merge this PR. For other open PRs, I have questions that I will ask in the near future, so I do not mention them here. |
|
Would you object to adjusting the release process such that we create official branches for each new release that can accept backports directly, rather than encumbering work on The process at my day job uses GHA to automate the process like so:
(two CI jobs, "create new release branch" and "publish new release"
The release process for new minor releases then consists of running the two jobs in sequence, and for new patch releases consists of running only the second job (as no new branch is needed) |
|
In fact, we do this (at least, I 😄 ), it's just that this process is not automated. It was required only 2 times (for 0.23 and 0.39), and I didn't want to tinker with automation for this. In addition, while we are in the 0.x release cycle, there are unlikely to be many patch changes for this automation to be required. Almost everything important requires a change of minor version, so it just naturally continues to grow from master. |
|
Well, I will see if #982 can be resolved this weekend, if not I will fork off a branch for it to land on later. |
Cow<[u8]>toCow<str>, remove DecoderCow<[u8]>toCow<str>