Skip to content

Commit

Permalink
String decoding: go through URBP directly instead of Slice (apple#639)
Browse files Browse the repository at this point in the history
Motivation:

String decoding can work faster when going through URBP directly instead
of a Slice of a URBP. The reason is that if the String has the utf8
represenation stored directly it'll just be a memcpy (+ validation).

Modifications:

go through URBP when decoding a String using String(decoding:as:)

Result:

faster if the String utf8 representation happens to be available
  • Loading branch information
weissi authored and Lukasa committed Oct 30, 2018
1 parent 287d50c commit ee9a229
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/NIO/ByteBuffer-aux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ extension ByteBuffer {
guard index <= pointer.count - length else {
return nil
}
return String(decoding: pointer[index..<(index+length)], as: UTF8.self)
return String(decoding: UnsafeRawBufferPointer(rebasing: pointer[index..<(index+length)]), as: UTF8.self)
}
}

Expand Down

0 comments on commit ee9a229

Please sign in to comment.