[librsvg: 5/14] rsvg_node_chars_append(): Don't copy the string; assume it comes validated from libxml2
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 5/14] rsvg_node_chars_append(): Don't copy the string; assume it comes validated from libxml2
- Date: Wed, 24 Jan 2018 19:07:36 +0000 (UTC)
commit 073fffdb81a9d133b9a37f9fcf689cdd31f9ba0d
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Jan 24 11:13:52 2018 -0600
rsvg_node_chars_append(): Don't copy the string; assume it comes validated from libxml2
rust/src/chars.rs | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/rust/src/chars.rs b/rust/src/chars.rs
index ef0dcb8..d94d48b 100644
--- a/rust/src/chars.rs
+++ b/rust/src/chars.rs
@@ -1,6 +1,7 @@
use libc;
use std;
use std::cell::RefCell;
+use std::str;
use drawing_ctx::{self, RsvgDrawingCtx};
use handle::RsvgHandle;
@@ -85,16 +86,13 @@ pub extern fn rsvg_node_chars_append(raw_node: *const RsvgNode,
assert!(!text.is_null());
assert!(len >= 0);
- // We don't use from_glib to convert the text here, since we are
- // not sure that it actually is valid UTF-8. We can't use CStr
- // because we are not getting passed nul-terminated data. We'll
- // do this by hand instead.
-
+ // libxml2 already validated the incoming string as UTF-8. Note that
+ // it is *not* nul-terminated; this is why we create a byte slice first.
let bytes = unsafe { std::slice::from_raw_parts(text as *const u8, len as usize) };
- let utf8 = String::from_utf8_lossy(bytes);
+ let utf8 = unsafe { str::from_utf8_unchecked(bytes) };
node.with_impl(|chars: &NodeChars| {
- chars.append(&utf8);
+ chars.append(utf8);
});
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]