From b14931088364b613733ee839be11602cd11e6984 Mon Sep 17 00:00:00 2001 From: Lonng Date: Tue, 16 Jul 2019 17:04:05 +0800 Subject: [PATCH] coprocessor: move 'is_unsigned' to 'FieldTypeAccessor' (#5095) Signed-off-by: Lonng --- components/cop_datatype/src/def/field_type.rs | 5 +++++ src/coprocessor/dag/rpn_expr/impl_cast.rs | 9 ++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/cop_datatype/src/def/field_type.rs b/components/cop_datatype/src/def/field_type.rs index 726b4068346..537f7f7599d 100644 --- a/components/cop_datatype/src/def/field_type.rs +++ b/components/cop_datatype/src/def/field_type.rs @@ -193,6 +193,11 @@ pub trait FieldTypeAccessor { fn is_non_binary_string_like(&self) -> bool { self.collation() != Collation::Binary && self.is_string_like() } + + /// Whether the flag contains `FieldTypeFlag::UNSIGNED` + fn is_unsigned(&self) -> bool { + self.flag().contains(FieldTypeFlag::UNSIGNED) + } } impl FieldTypeAccessor for FieldType { diff --git a/src/coprocessor/dag/rpn_expr/impl_cast.rs b/src/coprocessor/dag/rpn_expr/impl_cast.rs index 1ef6b4dabf9..4f13cdae13f 100644 --- a/src/coprocessor/dag/rpn_expr/impl_cast.rs +++ b/src/coprocessor/dag/rpn_expr/impl_cast.rs @@ -3,7 +3,7 @@ use std::convert::TryFrom; use cop_codegen::rpn_fn; -use cop_datatype::{EvalType, FieldTypeAccessor, FieldTypeFlag}; +use cop_datatype::{EvalType, FieldTypeAccessor}; use tipb::expression::FieldType; use crate::coprocessor::codec::data_type::*; @@ -23,7 +23,7 @@ pub fn get_cast_fn_rpn_node( let to = box_try!(EvalType::try_from(to_field_type.tp())); let func_meta = match (from, to) { (EvalType::Int, EvalType::Decimal) => { - if !is_unsigned(from_field_type) && !is_unsigned(&to_field_type) { + if !from_field_type.is_unsigned() && !to_field_type.is_unsigned() { cast_int_as_decimal_fn_meta() } else { cast_uint_as_decimal_fn_meta() @@ -47,11 +47,6 @@ pub fn get_cast_fn_rpn_node( }) } -#[inline] -fn is_unsigned(ft: &FieldType) -> bool { - ft.as_accessor().flag().contains(FieldTypeFlag::UNSIGNED) -} - fn produce_dec_with_specified_tp( ctx: &mut EvalContext, dec: Decimal,