Skip to content

Commit 9fbd87f

Browse files
authored
refactor: replace OnceLock with LazyLock (#13641)
* refactor: Replace OnceLock with LazyLock * Fix typo
1 parent dd242b9 commit 9fbd87f

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

datafusion/common/src/types/builtin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
// under the License.
1717

1818
use crate::types::{LogicalTypeRef, NativeType};
19-
use std::sync::{Arc, OnceLock};
19+
use std::sync::{Arc, LazyLock};
2020

2121
macro_rules! singleton {
2222
($name:ident, $getter:ident, $ty:ident) => {
23-
// TODO: Use LazyLock instead of getter function when MSRV gets bumped
24-
static $name: OnceLock<LogicalTypeRef> = OnceLock::new();
23+
static $name: LazyLock<LogicalTypeRef> =
24+
LazyLock::new(|| Arc::new(NativeType::$ty));
2525

2626
#[doc = "Getter for singleton instance of a logical type representing"]
2727
#[doc = concat!("[`NativeType::", stringify!($ty), "`].")]
2828
pub fn $getter() -> LogicalTypeRef {
29-
Arc::clone($name.get_or_init(|| Arc::new(NativeType::$ty)))
29+
Arc::clone(&$name)
3030
}
3131
};
3232
}

datafusion/expr/src/logical_plan/statement.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@
1818
use arrow::datatypes::DataType;
1919
use datafusion_common::{DFSchema, DFSchemaRef};
2020
use std::fmt::{self, Display};
21-
use std::sync::{Arc, OnceLock};
21+
use std::sync::{Arc, LazyLock};
2222

2323
use crate::{expr_vec_fmt, Expr, LogicalPlan};
2424

25-
/// Statements have a unchanging empty schema.
26-
/// TODO: Use `LazyLock` when MSRV is 1.80.0
27-
static STATEMENT_EMPTY_SCHEMA: OnceLock<DFSchemaRef> = OnceLock::new();
28-
2925
/// Various types of Statements.
3026
///
3127
/// # Transactions:
@@ -54,7 +50,11 @@ pub enum Statement {
5450
impl Statement {
5551
/// Get a reference to the logical plan's schema
5652
pub fn schema(&self) -> &DFSchemaRef {
57-
STATEMENT_EMPTY_SCHEMA.get_or_init(|| Arc::new(DFSchema::empty()))
53+
// Statements have an unchanging empty schema.
54+
static STATEMENT_EMPTY_SCHEMA: LazyLock<DFSchemaRef> =
55+
LazyLock::new(|| Arc::new(DFSchema::empty()));
56+
57+
&STATEMENT_EMPTY_SCHEMA
5858
}
5959

6060
/// Return a descriptive string describing the type of this

0 commit comments

Comments
 (0)