Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Replace fn Offset::is_large() as const Offset::IS_LARGE #1002

Merged
merged 1 commit into from May 21, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/array/binary/fmt.rs
Expand Up @@ -15,7 +15,7 @@ impl<O: Offset> Debug for BinaryArray<O> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let writer = |f: &mut Formatter, index| write_value(self, index, f);

let head = if O::is_large() {
let head = if O::IS_LARGE {
"LargeBinaryArray"
} else {
"BinaryArray"
Expand Down
2 changes: 1 addition & 1 deletion src/array/binary/mod.rs
Expand Up @@ -124,7 +124,7 @@ impl<O: Offset> BinaryArray<O> {

/// Returns the default [`DataType`], `DataType::Binary` or `DataType::LargeBinary`
pub fn default_data_type() -> DataType {
if O::is_large() {
if O::IS_LARGE {
DataType::LargeBinary
} else {
DataType::Binary
Expand Down
2 changes: 1 addition & 1 deletion src/array/list/fmt.rs
Expand Up @@ -20,7 +20,7 @@ impl<O: Offset> Debug for ListArray<O> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let writer = |f: &mut Formatter, index| write_value(self, index, "None", f);

let head = if O::is_large() {
let head = if O::IS_LARGE {
"LargeListArray"
} else {
"ListArray"
Expand Down
4 changes: 2 additions & 2 deletions src/array/list/mod.rs
Expand Up @@ -292,7 +292,7 @@ impl<O: Offset> ListArray<O> {
/// Returns a default [`DataType`]: inner field is named "item" and is nullable
pub fn default_datatype(data_type: DataType) -> DataType {
let field = Box::new(Field::new("item", data_type, true));
if O::is_large() {
if O::IS_LARGE {
DataType::LargeList(field)
} else {
DataType::List(field)
Expand All @@ -310,7 +310,7 @@ impl<O: Offset> ListArray<O> {
/// # Errors
/// Panics iff the logical type is not consistent with this struct.
fn try_get_child(data_type: &DataType) -> Result<&Field, ArrowError> {
if O::is_large() {
if O::IS_LARGE {
match data_type.to_logical_type() {
DataType::LargeList(child) => Ok(child.as_ref()),
_ => Err(ArrowError::oos(
Expand Down
2 changes: 1 addition & 1 deletion src/array/list/mutable.rs
Expand Up @@ -110,7 +110,7 @@ impl<O: Offset, M: MutableArray> MutableListArray<O, M> {
/// Creates a new [`MutableListArray`] from a [`MutableArray`].
pub fn new_with_field(values: M, name: &str, nullable: bool) -> Self {
let field = Box::new(Field::new(name, values.data_type().clone(), nullable));
let data_type = if O::is_large() {
let data_type = if O::IS_LARGE {
DataType::LargeList(field)
} else {
DataType::List(field)
Expand Down
2 changes: 1 addition & 1 deletion src/array/utf8/fmt.rs
Expand Up @@ -12,7 +12,7 @@ impl<O: Offset> Debug for Utf8Array<O> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let writer = |f: &mut Formatter, index| write_value(self, index, f);

let head = if O::is_large() {
let head = if O::IS_LARGE {
"LargeUtf8Array"
} else {
"Utf8Array"
Expand Down
2 changes: 1 addition & 1 deletion src/array/utf8/mod.rs
Expand Up @@ -142,7 +142,7 @@ impl<O: Offset> Utf8Array<O> {

/// Returns the default [`DataType`], `DataType::Utf8` or `DataType::LargeUtf8`
pub fn default_data_type() -> DataType {
if O::is_large() {
if O::IS_LARGE {
DataType::LargeUtf8
} else {
DataType::Utf8
Expand Down
2 changes: 1 addition & 1 deletion src/array/utf8/mutable.rs
Expand Up @@ -265,7 +265,7 @@ impl<O: Offset> MutableArray for MutableUtf8Array<O> {
}

fn data_type(&self) -> &DataType {
if O::is_large() {
if O::IS_LARGE {
&DataType::LargeUtf8
} else {
&DataType::Utf8
Expand Down
2 changes: 1 addition & 1 deletion src/compute/length.rs
Expand Up @@ -35,7 +35,7 @@ where
.map(|offset| op(offset[1] - offset[0]))
.collect::<Vec<_>>();

let data_type = if O::is_large() {
let data_type = if O::IS_LARGE {
DataType::Int64
} else {
DataType::Int32
Expand Down
2 changes: 1 addition & 1 deletion src/scalar/binary.rs
Expand Up @@ -46,7 +46,7 @@ impl<O: Offset> Scalar for BinaryScalar<O> {

#[inline]
fn data_type(&self) -> &DataType {
if O::is_large() {
if O::IS_LARGE {
&DataType::LargeBinary
} else {
&DataType::Binary
Expand Down
2 changes: 1 addition & 1 deletion src/scalar/utf8.rs
Expand Up @@ -46,7 +46,7 @@ impl<O: Offset> Scalar for Utf8Scalar<O> {

#[inline]
fn data_type(&self) -> &DataType {
if O::is_large() {
if O::IS_LARGE {
&DataType::LargeUtf8
} else {
&DataType::Utf8
Expand Down
12 changes: 3 additions & 9 deletions src/types/offset.rs
Expand Up @@ -4,19 +4,13 @@ use super::Index;
/// as offsets of variable-length Arrow arrays.
pub trait Offset: super::private::Sealed + Index {
/// Whether it is `i32` (false) or `i64` (true).
fn is_large() -> bool;
const IS_LARGE: bool;
}

impl Offset for i32 {
#[inline]
fn is_large() -> bool {
false
}
const IS_LARGE: bool = false;
}

impl Offset for i64 {
#[inline]
fn is_large() -> bool {
true
}
const IS_LARGE: bool = true;
}
2 changes: 1 addition & 1 deletion tests/it/compute/length.rs
Expand Up @@ -15,7 +15,7 @@ fn length_test_string<O: Offset>() {
let array = Utf8Array::<O>::from(&input);
let result = length(&array).unwrap();

let data_type = if O::is_large() {
let data_type = if O::IS_LARGE {
DataType::Int64
} else {
DataType::Int32
Expand Down