Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary cloning #572

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 38 additions & 22 deletions src/lib.rs
Expand Up @@ -985,6 +985,11 @@ impl<'a> RecordBuilder<'a> {
pub fn build(&self) -> Record<'a> {
self.record.clone()
}

#[inline]
fn into_record(self) -> Record<'a> {
self.record
}
}

impl<'a> Default for RecordBuilder<'a> {
Expand Down Expand Up @@ -1114,6 +1119,11 @@ impl<'a> MetadataBuilder<'a> {
pub fn build(&self) -> Metadata<'a> {
self.metadata.clone()
}

#[inline]
fn into_metadata(self) -> Metadata<'a> {
self.metadata
}
}

impl<'a> Default for MetadataBuilder<'a> {
Expand Down Expand Up @@ -1479,16 +1489,17 @@ pub fn __private_api_log(
)
}

logger().log(
&Record::builder()
.args(args)
.level(level)
.target(target)
.module_path_static(Some(module_path))
.file_static(Some(file))
.line(Some(line))
.build(),
);
let mut builder = Record::builder();

builder
.args(args)
.level(level)
.target(target)
.module_path_static(Some(module_path))
.file_static(Some(file))
.line(Some(line));

logger().log(&builder.into_record());
}

// WARNING: this is not part of the crate's public API and is subject to change at any time
Expand All @@ -1500,23 +1511,28 @@ pub fn __private_api_log(
&(target, module_path, file, line): &(&str, &'static str, &'static str, u32),
kvs: Option<&[(&str, &dyn kv::ToValue)]>,
) {
logger().log(
&Record::builder()
.args(args)
.level(level)
.target(target)
.module_path_static(Some(module_path))
.file_static(Some(file))
.line(Some(line))
.key_values(&kvs)
.build(),
);
let mut builder = Record::builder();

builder
.args(args)
.level(level)
.target(target)
.module_path_static(Some(module_path))
.file_static(Some(file))
.line(Some(line))
.key_values(&kvs);

logger().log(&builder.into_record());
}

// WARNING: this is not part of the crate's public API and is subject to change at any time
#[doc(hidden)]
pub fn __private_api_enabled(level: Level, target: &str) -> bool {
logger().enabled(&Metadata::builder().level(level).target(target).build())
let mut builder = Metadata::builder();

builder.level(level).target(target);

logger().enabled(&builder.into_metadata())
}

// WARNING: this is not part of the crate's public API and is subject to change at any time
Expand Down