Skip to content

Commit

Permalink
refactor: replace OnceLock with LazyLock (apache#13641)
Browse files Browse the repository at this point in the history
* refactor: Replace OnceLock with LazyLock

* Fix typo
  • Loading branch information
jonahgao authored Dec 4, 2024
1 parent dd242b9 commit 9fbd87f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions datafusion/common/src/types/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
// under the License.

use crate::types::{LogicalTypeRef, NativeType};
use std::sync::{Arc, OnceLock};
use std::sync::{Arc, LazyLock};

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

#[doc = "Getter for singleton instance of a logical type representing"]
#[doc = concat!("[`NativeType::", stringify!($ty), "`].")]
pub fn $getter() -> LogicalTypeRef {
Arc::clone($name.get_or_init(|| Arc::new(NativeType::$ty)))
Arc::clone(&$name)
}
};
}
Expand Down
12 changes: 6 additions & 6 deletions datafusion/expr/src/logical_plan/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
use arrow::datatypes::DataType;
use datafusion_common::{DFSchema, DFSchemaRef};
use std::fmt::{self, Display};
use std::sync::{Arc, OnceLock};
use std::sync::{Arc, LazyLock};

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

/// Statements have a unchanging empty schema.
/// TODO: Use `LazyLock` when MSRV is 1.80.0
static STATEMENT_EMPTY_SCHEMA: OnceLock<DFSchemaRef> = OnceLock::new();

/// Various types of Statements.
///
/// # Transactions:
Expand Down Expand Up @@ -54,7 +50,11 @@ pub enum Statement {
impl Statement {
/// Get a reference to the logical plan's schema
pub fn schema(&self) -> &DFSchemaRef {
STATEMENT_EMPTY_SCHEMA.get_or_init(|| Arc::new(DFSchema::empty()))
// Statements have an unchanging empty schema.
static STATEMENT_EMPTY_SCHEMA: LazyLock<DFSchemaRef> =
LazyLock::new(|| Arc::new(DFSchema::empty()));

&STATEMENT_EMPTY_SCHEMA
}

/// Return a descriptive string describing the type of this
Expand Down

0 comments on commit 9fbd87f

Please sign in to comment.