Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Resolve "xs:list deserialization does not split on all whitespace" #843

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JGM01
Copy link

@JGM01 JGM01 commented Feb 1, 2025

Changed DELIMITER (u8) into an array DELIMITERS (u8; 4) that holds 4 possible delimiters.

This was implemented with issue #839 in mind, so I covered the following whitespaces: , \t, \r, \n. It is fairly easy to include more if necessary.


loop {
let string = content.as_str();
if string.is_empty() {
return Ok(None);
}
return match memchr(DELIMITER, string.as_bytes()) {

let first_delimiter = string.as_bytes().iter().position(|c| DELIMETERS.contains(c));
Copy link
Contributor

Choose a reason for hiding this comment

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

str::find will accept an array of characters and give you the first matching position which is likely faster than iterating bytes.

Alternatively, two calls to memchr2 might be an alternative that might be a bit faster yet.

@@ -391,7 +393,7 @@ impl<'de, 'a> SeqAccess<'de> for ListIter<'de, 'a> {
// `content` started with a space, skip them all
Some(0) => {
// Skip all spaces
let start = string.as_bytes().iter().position(|ch| *ch != DELIMITER);
let start = string.as_bytes().iter().position(|c| !DELIMETERS.contains(c));
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the above, str::find also accepts a closure checking whether a character matches.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants