mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-01-09 08:45:27 +00:00
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"
|
paste = "1.0"
|
||||||
pretty-hex = "0.3"
|
pretty-hex = "0.3"
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
|
smallvec = { version = "1.0", features = ["write"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
ron = "0.8"
|
ron = "0.8"
|
||||||
|
|
|
@ -279,21 +279,17 @@ impl DebugCategory {
|
||||||
line: u32,
|
line: u32,
|
||||||
args: fmt::Arguments,
|
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
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
w.push(0);
|
||||||
|
|
||||||
self.log_literal_unfiltered_internal(
|
self.log_literal_unfiltered_internal(obj, level, file, function, line, unsafe {
|
||||||
obj,
|
glib::GStr::from_utf8_with_nul_unchecked(&w)
|
||||||
level,
|
});
|
||||||
file,
|
|
||||||
function,
|
|
||||||
line,
|
|
||||||
w.into_string().as_gstr(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
|
@ -432,21 +428,16 @@ impl DebugCategory {
|
||||||
line: u32,
|
line: u32,
|
||||||
args: fmt::Arguments,
|
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
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.log_id_literal_unfiltered_internal(
|
self.log_id_literal_unfiltered_internal(id, level, file, function, line, unsafe {
|
||||||
id,
|
glib::GStr::from_utf8_with_nul_unchecked(&w)
|
||||||
level,
|
});
|
||||||
file,
|
|
||||||
function,
|
|
||||||
line,
|
|
||||||
w.into_string().as_gstr(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "v1_22", feature = "dox"))]
|
#[cfg(any(feature = "v1_22", feature = "dox"))]
|
||||||
|
|
Loading…
Reference in a new issue