stringprep can make transformations to a JID, the most well-known one is
making the nodepart and domainpart lowercase but it does much more than
that.
It is extremely common to have to validate already-normalised JIDs
though, and since https://github.com/sfackler/rust-stringprep/pull/4
this is exactly what the stringprep crate does, by returning
Cow::Borrowed() for common ASCII-only cases.
This commit further reduces time spent by an additional -15%..-58% when
already using this stringprep improvement, in addition to the
89.5%..98.5% change brought by this improvement (and +1.3% total when
the JID isn’t normalised yet).
For instance, my own full JID parses in 1.83 µs before these changes,
132 ns with just the stringprep optimisation, and 46 ns with also this
commit, on an i7-8700K.
This needs to be a loop in order to ignore packets we don’t care about,
or those we want to handle elsewhere. Returning something isn’t correct
in those two cases because it would signal to tokio that the XMPPStream
is also done, while there could be additional packets waiting for us.
The proper solution is thus a loop which we exit once we have something
to return.
Fixes a deadlock when we ignore some packets.
The main reason for this refactor was to make common operations simpler,
for instance formatting a JID is now a simple clone of a String.
Instead of having three different String for each of node, domain and
resource, we now have a single String with offsets pointing to where the
at and slash are (if they are present).
This also reduces the size of a FullJid from 72 bytes to 32 bytes on
64-bit platforms (less so on 32-bit), and BareJid from 48 bytes to
32 bytes. Jid is still 40 bytes instead of 32, but that can be improved
in a future version where InnerJid has been inlined into each struct.
This dependency is unmaintained, but it is written in pure Rust unlike
ICU, and doesn’t require a roundtrip through UTF-16, improving both
performances (perhaps?) and ease of compilation.
The previous commit didn't fix a bug where @id would be added to
elements that didn't need it / where it was invalid (e.g., stream
management).
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit moves the code adding @id to AsyncClient and SimpleClient,
instead of on the lower level send_stanza helper, which seemed to only
be used internally.
Support is also added for Component.
This removes the addition of @id on elements like <auth/> or <bind/>,
which probably weren't required anyway?
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>