forked from mirrors/gstreamer-rs
gstreamer: Allocate debug messages up to 256 bytes on the stack and only then spill over into the heap
With this, debug logging from Rust is completely allocation-less for short messages and string literals. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1179>
This commit is contained in:
parent
06a0dbacba
commit
ae688406f8
2 changed files with 12 additions and 20 deletions
|
@ -32,6 +32,7 @@ serde_bytes = { version = "0.11", optional = true }
|
|||
paste = "1.0"
|
||||
pretty-hex = "0.3"
|
||||
thiserror = "1"
|
||||
smallvec = { version = "1.0", features = ["write"] }
|
||||
|
||||
[dev-dependencies]
|
||||
ron = "0.8"
|
||||
|
|
|
@ -279,21 +279,17 @@ impl DebugCategory {
|
|||
line: u32,
|
||||
args: fmt::Arguments,
|
||||
) {
|
||||
let mut w = glib::GStringBuilder::default();
|
||||
let mut w = smallvec::SmallVec::<[u8; 256]>::new();
|
||||
|
||||
// Can't really happen but better safe than sorry
|
||||
if fmt::write(&mut w, args).is_err() {
|
||||
if std::io::Write::write_fmt(&mut w, args).is_err() {
|
||||
return;
|
||||
}
|
||||
w.push(0);
|
||||
|
||||
self.log_literal_unfiltered_internal(
|
||||
obj,
|
||||
level,
|
||||
file,
|
||||
function,
|
||||
line,
|
||||
w.into_string().as_gstr(),
|
||||
);
|
||||
self.log_literal_unfiltered_internal(obj, level, file, function, line, unsafe {
|
||||
glib::GStr::from_utf8_with_nul_unchecked(&w)
|
||||
});
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
|
@ -432,21 +428,16 @@ impl DebugCategory {
|
|||
line: u32,
|
||||
args: fmt::Arguments,
|
||||
) {
|
||||
let mut w = glib::GStringBuilder::default();
|
||||
let mut w = smallvec::SmallVec::<[u8; 256]>::new();
|
||||
|
||||
// Can't really happen but better safe than sorry
|
||||
if fmt::write(&mut w, args).is_err() {
|
||||
if std::io::Write::write_fmt(&mut w, args).is_err() {
|
||||
return;
|
||||
}
|
||||
|
||||
self.log_id_literal_unfiltered_internal(
|
||||
id,
|
||||
level,
|
||||
file,
|
||||
function,
|
||||
line,
|
||||
w.into_string().as_gstr(),
|
||||
);
|
||||
self.log_id_literal_unfiltered_internal(id, level, file, function, line, unsafe {
|
||||
glib::GStr::from_utf8_with_nul_unchecked(&w)
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_22", feature = "dox"))]
|
||||
|
|
Loading…
Reference in a new issue