mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 11:01:10 +00:00
gstreamer: Reduce some allocations for passing the filename/module name to the logging functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160>
This commit is contained in:
parent
750422d8eb
commit
3a61276cdd
2 changed files with 60 additions and 28 deletions
|
@ -127,8 +127,8 @@ impl LoggableError {
|
|||
self.category.log(
|
||||
None as Option<&glib::Object>,
|
||||
crate::DebugLevel::Error,
|
||||
self.bool_error.filename,
|
||||
self.bool_error.function,
|
||||
glib::GString::from(self.bool_error.filename).as_gstr(),
|
||||
glib::GString::from(self.bool_error.function).as_gstr(),
|
||||
self.bool_error.line,
|
||||
format_args!("{}", self.bool_error.message),
|
||||
);
|
||||
|
@ -138,8 +138,8 @@ impl LoggableError {
|
|||
self.category.log(
|
||||
Some(obj),
|
||||
crate::DebugLevel::Error,
|
||||
self.bool_error.filename,
|
||||
self.bool_error.function,
|
||||
glib::GString::from(self.bool_error.filename).as_gstr(),
|
||||
glib::GString::from(self.bool_error.function).as_gstr(),
|
||||
self.bool_error.line,
|
||||
format_args!("{}", self.bool_error.message),
|
||||
);
|
||||
|
@ -151,8 +151,8 @@ impl LoggableError {
|
|||
self.category.log(
|
||||
Some(unsafe { imp.obj().unsafe_cast_ref::<glib::Object>() }),
|
||||
crate::DebugLevel::Error,
|
||||
self.bool_error.filename,
|
||||
self.bool_error.function,
|
||||
glib::GString::from(self.bool_error.filename).as_gstr(),
|
||||
glib::GString::from(self.bool_error.function).as_gstr(),
|
||||
self.bool_error.line,
|
||||
format_args!("{}", self.bool_error.message),
|
||||
);
|
||||
|
|
|
@ -170,8 +170,8 @@ impl DebugCategory {
|
|||
self,
|
||||
obj: Option<&O>,
|
||||
level: crate::DebugLevel,
|
||||
file: &str,
|
||||
module: &str,
|
||||
file: &glib::GStr,
|
||||
module: &glib::GStr,
|
||||
line: u32,
|
||||
args: fmt::Arguments,
|
||||
) {
|
||||
|
@ -198,8 +198,8 @@ impl DebugCategory {
|
|||
self,
|
||||
obj: Option<&O>,
|
||||
level: crate::DebugLevel,
|
||||
file: &str,
|
||||
module: &str,
|
||||
file: &glib::GStr,
|
||||
module: &glib::GStr,
|
||||
line: u32,
|
||||
args: fmt::Arguments,
|
||||
) {
|
||||
|
@ -225,8 +225,8 @@ impl DebugCategory {
|
|||
ffi::gst_debug_log_literal(
|
||||
cat.as_ptr(),
|
||||
level.into_glib(),
|
||||
file.to_glib_none().0,
|
||||
module.to_glib_none().0,
|
||||
file.as_ptr(),
|
||||
module.as_ptr(),
|
||||
line as i32,
|
||||
obj_ptr,
|
||||
w.into_string().to_glib_none().0,
|
||||
|
@ -237,8 +237,8 @@ impl DebugCategory {
|
|||
ffi::gst_debug_log(
|
||||
cat.as_ptr(),
|
||||
level.into_glib(),
|
||||
file.to_glib_none().0,
|
||||
module.to_glib_none().0,
|
||||
file.as_ptr(),
|
||||
module.as_ptr(),
|
||||
line as i32,
|
||||
obj_ptr,
|
||||
b"%s\0".as_ptr() as *const _,
|
||||
|
@ -256,8 +256,8 @@ impl DebugCategory {
|
|||
self,
|
||||
id: Option<&str>,
|
||||
level: crate::DebugLevel,
|
||||
file: &str,
|
||||
module: &str,
|
||||
file: &glib::GStr,
|
||||
module: &glib::GStr,
|
||||
line: u32,
|
||||
args: fmt::Arguments,
|
||||
) {
|
||||
|
@ -293,8 +293,8 @@ impl DebugCategory {
|
|||
self,
|
||||
id: Option<&str>,
|
||||
level: crate::DebugLevel,
|
||||
file: &str,
|
||||
module: &str,
|
||||
file: &glib::GStr,
|
||||
module: &glib::GStr,
|
||||
line: u32,
|
||||
args: fmt::Arguments,
|
||||
) {
|
||||
|
@ -314,8 +314,8 @@ impl DebugCategory {
|
|||
ffi::gst_debug_log_id_literal(
|
||||
cat.as_ptr(),
|
||||
level.into_glib(),
|
||||
file.to_glib_none().0,
|
||||
module.to_glib_none().0,
|
||||
file.as_ptr(),
|
||||
module.as_ptr(),
|
||||
line as i32,
|
||||
id.to_glib_none().0,
|
||||
w.into_string().to_glib_none().0,
|
||||
|
@ -565,42 +565,74 @@ macro_rules! log_with_level(
|
|||
($cat:expr, level: $level:expr, obj: $obj:expr, $($args:tt)*) => { {
|
||||
// Check the log level before using `format_args!` otherwise
|
||||
// formatted arguments are evaluated even if we end up not logging.
|
||||
#[allow(unused_unsafe)]
|
||||
if $level <= $cat.threshold() {
|
||||
use $crate::glib::Cast;
|
||||
|
||||
#[allow(unused_unsafe)]
|
||||
let obj = unsafe { $obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
||||
$crate::DebugCategory::log_unfiltered($cat.clone(), Some(obj),
|
||||
$level, file!(), module_path!(), line!(), format_args!($($args)*))
|
||||
$crate::DebugCategory::log_unfiltered(
|
||||
$cat.clone(),
|
||||
Some(obj),
|
||||
$level,
|
||||
unsafe { $crate::glib::GStr::from_bytes_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
||||
unsafe { $crate::glib::GStr::from_bytes_with_nul_unchecked(concat!(module_path!(), "\0").as_bytes()) },
|
||||
line!(),
|
||||
format_args!($($args)*),
|
||||
)
|
||||
}
|
||||
}};
|
||||
($cat:expr, level: $level:expr, imp: $imp:expr, $($args:tt)*) => { {
|
||||
// Check the log level before using `format_args!` otherwise
|
||||
// formatted arguments are evaluated even if we end up not logging.
|
||||
#[allow(unused_unsafe)]
|
||||
if $level <= $cat.threshold() {
|
||||
use $crate::glib::Cast;
|
||||
|
||||
let obj = $imp.obj();
|
||||
#[allow(unused_unsafe)]
|
||||
let obj = unsafe { obj.unsafe_cast_ref::<$crate::glib::Object>() };
|
||||
$crate::DebugCategory::log_unfiltered($cat.clone(), Some(obj),
|
||||
$level, file!(), module_path!(), line!(), format_args!($($args)*))
|
||||
$crate::DebugCategory::log_unfiltered(
|
||||
$cat.clone(),
|
||||
Some(obj),
|
||||
$level,
|
||||
unsafe { $crate::glib::GStr::from_bytes_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
||||
unsafe { $crate::glib::GStr::from_bytes_with_nul_unchecked(concat!(module_path!(), "\0").as_bytes()) },
|
||||
line!(),
|
||||
format_args!($($args)*),
|
||||
)
|
||||
}
|
||||
}};
|
||||
($cat:expr, level: $level:expr, id: $id:expr, $($args:tt)*) => { {
|
||||
// Check the log level before using `format_args!` otherwise
|
||||
// formatted arguments are evaluated even if we end up not logging.
|
||||
#[allow(unused_unsafe)]
|
||||
if $level <= $cat.threshold() {
|
||||
$crate::DebugCategory::log_id_unfiltered($cat.clone(), Some($id),
|
||||
$level, file!(), module_path!(), line!(), format_args!($($args)*))
|
||||
$crate::DebugCategory::log_id_unfiltered(
|
||||
$cat.clone(),
|
||||
Some($id),
|
||||
$level,
|
||||
unsafe { $crate::glib::GStr::from_bytes_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
||||
unsafe { $crate::glib::GStr::from_bytes_with_nul_unchecked(concat!(module_path!(), "\0").as_bytes()) },
|
||||
line!(),
|
||||
format_args!($($args)*),
|
||||
)
|
||||
}
|
||||
}};
|
||||
($cat:expr, level: $level:expr, $($args:tt)*) => { {
|
||||
// Check the log level before using `format_args!` otherwise
|
||||
// formatted arguments are evaluated even if we end up not logging.
|
||||
#[allow(unused_unsafe)]
|
||||
if $level <= $cat.threshold() {
|
||||
$crate::DebugCategory::log_unfiltered($cat.clone(), None as Option<&$crate::glib::Object>,
|
||||
$level, file!(), module_path!(), line!(), format_args!($($args)*))
|
||||
$crate::DebugCategory::log_unfiltered(
|
||||
$cat.clone(),
|
||||
None as Option<&$crate::glib::Object>,
|
||||
$level,
|
||||
unsafe { $crate::glib::GStr::from_bytes_with_nul_unchecked(concat!(file!(), "\0").as_bytes()) },
|
||||
unsafe { $crate::glib::GStr::from_bytes_with_nul_unchecked(concat!(module_path!(), "\0").as_bytes()) },
|
||||
line!(),
|
||||
format_args!($($args)*),
|
||||
)
|
||||
}
|
||||
}};
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue