-
Notifications
You must be signed in to change notification settings - Fork 243
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
JGM01
wants to merge
1
commit into
tafia:master
Choose a base branch
from
JGM01:splitOnAllWhitespace
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ use crate::encoding::Decoder; | |
use crate::errors::serialize::DeError; | ||
use crate::escape::unescape; | ||
use crate::utils::CowRef; | ||
use memchr::memchr; | ||
use serde::de::value::UnitDeserializer; | ||
use serde::de::{ | ||
DeserializeSeed, Deserializer, EnumAccess, IntoDeserializer, SeqAccess, VariantAccess, Visitor, | ||
|
@@ -361,14 +360,17 @@ impl<'de, 'a> SeqAccess<'de> for ListIter<'de, 'a> { | |
T: DeserializeSeed<'de>, | ||
{ | ||
if let Some(mut content) = self.content.take() { | ||
const DELIMITER: u8 = b' '; | ||
const DELIMETERS: [u8; 4] = [b' ', b'\t', b'\r', b'\n']; | ||
|
||
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)); | ||
|
||
return match first_delimiter { | ||
// No delimiters in the `content`, deserialize it as a whole atomic | ||
None => match content { | ||
Content::Input(s) => seed.deserialize(AtomicDeserializer { | ||
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the above, |
||
content = match (start, content) { | ||
// We cannot find any non-space character, so string contains only spaces | ||
(None, _) => return Ok(None), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.