This is an automated email from the ASF dual-hosted git repository.

CurtHagenlocher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-dotnet.git


The following commit(s) were added to refs/heads/main by this push:
     new fa96808  Remove static array (#384)
fa96808 is described below

commit fa968084845d5eceec5b27259da87d935c01e48d
Author: kronic <[email protected]>
AuthorDate: Tue Jul 7 01:02:52 2026 +0700

    Remove static array (#384)
    
    remove static array
---
 src/Apache.Arrow/Types/DurationType.cs | 13 +++++++++----
 src/Apache.Arrow/Types/IntervalType.cs | 10 ++++++----
 src/Apache.Arrow/Types/TimeType.cs     | 13 +++++++++----
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/src/Apache.Arrow/Types/DurationType.cs 
b/src/Apache.Arrow/Types/DurationType.cs
index 7e937a6..9a725fb 100644
--- a/src/Apache.Arrow/Types/DurationType.cs
+++ b/src/Apache.Arrow/Types/DurationType.cs
@@ -13,6 +13,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+using System;
+
 namespace Apache.Arrow.Types
 {
     public sealed class DurationType : TimeBasedType
@@ -21,7 +23,6 @@ namespace Apache.Arrow.Types
         public static readonly DurationType Millisecond = new 
DurationType(TimeUnit.Millisecond);
         public static readonly DurationType Microsecond = new 
DurationType(TimeUnit.Microsecond);
         public static readonly DurationType Nanosecond = new 
DurationType(TimeUnit.Nanosecond);
-        private static readonly DurationType[] _types = new DurationType[] { 
Second, Millisecond, Microsecond, Nanosecond };
 
         private DurationType(TimeUnit unit)
             : base(unit)
@@ -32,10 +33,14 @@ namespace Apache.Arrow.Types
         public override string Name => "duration";
         public override int BitWidth => 64;
 
-        public static DurationType FromTimeUnit(TimeUnit unit)
+        public static DurationType FromTimeUnit(TimeUnit unit) => unit switch
         {
-            return _types[(int)unit];
-        }
+            TimeUnit.Second => Second,
+            TimeUnit.Millisecond => Millisecond,
+            TimeUnit.Microsecond => Microsecond,
+            TimeUnit.Nanosecond => Nanosecond,
+            _ => throw new ArgumentOutOfRangeException(nameof(unit), unit, 
@"Unsupported time unit.")
+        };
 
         public override void Accept(IArrowTypeVisitor visitor) => Accept(this, 
visitor);
     }
diff --git a/src/Apache.Arrow/Types/IntervalType.cs 
b/src/Apache.Arrow/Types/IntervalType.cs
index b8e1fde..14bf61f 100644
--- a/src/Apache.Arrow/Types/IntervalType.cs
+++ b/src/Apache.Arrow/Types/IntervalType.cs
@@ -22,7 +22,6 @@ namespace Apache.Arrow.Types
         public static readonly IntervalType YearMonth = new 
IntervalType(IntervalUnit.YearMonth);
         public static readonly IntervalType DayTime = new 
IntervalType(IntervalUnit.DayTime);
         public static readonly IntervalType MonthDayNanosecond = new 
IntervalType(IntervalUnit.MonthDayNanosecond);
-        private static readonly IntervalType[] _types = new IntervalType[] { 
YearMonth, DayTime, MonthDayNanosecond };
 
         public override ArrowTypeId TypeId => ArrowTypeId.Interval;
         public override string Name => "interval";
@@ -43,9 +42,12 @@ namespace Apache.Arrow.Types
 
         public override void Accept(IArrowTypeVisitor visitor) => Accept(this, 
visitor);
 
-        public static IntervalType FromIntervalUnit(IntervalUnit unit)
+        public static IntervalType FromIntervalUnit(IntervalUnit unit) => unit 
switch
         {
-            return _types[(int)unit];
-        }
+            IntervalUnit.YearMonth => YearMonth,
+            IntervalUnit.DayTime => DayTime,
+            IntervalUnit.MonthDayNanosecond => MonthDayNanosecond,
+            _ => throw new ArgumentOutOfRangeException(nameof(unit), unit, 
@"Unsupported interval unit")
+        };
     }
 }
diff --git a/src/Apache.Arrow/Types/TimeType.cs 
b/src/Apache.Arrow/Types/TimeType.cs
index b317df2..2ca612c 100644
--- a/src/Apache.Arrow/Types/TimeType.cs
+++ b/src/Apache.Arrow/Types/TimeType.cs
@@ -13,6 +13,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+using System;
+
 namespace Apache.Arrow.Types
 {
     public abstract class TimeType : TimeBasedType
@@ -21,16 +23,19 @@ namespace Apache.Arrow.Types
         public static readonly Time32Type Millisecond = new 
Time32Type(TimeUnit.Millisecond);
         public static readonly Time64Type Microsecond = new 
Time64Type(TimeUnit.Microsecond);
         public static readonly Time64Type Nanosecond = new 
Time64Type(TimeUnit.Nanosecond);
-        private static readonly TimeType[] _types = new TimeType[] { Second, 
Millisecond, Microsecond, Nanosecond };
 
         protected TimeType(TimeUnit unit)
             : base(unit)
         {
         }
 
-        public static TimeType FromTimeUnit(TimeUnit unit)
+        public static TimeType FromTimeUnit(TimeUnit unit) => unit switch
         {
-            return _types[(int)unit];
-        }
+            TimeUnit.Second => Second,
+            TimeUnit.Millisecond => Millisecond,
+            TimeUnit.Microsecond => Microsecond,
+            TimeUnit.Nanosecond => Nanosecond,
+            _ => throw new ArgumentOutOfRangeException(nameof(unit), unit, 
@"Unsupported time unit")
+        };
     }
 }

Reply via email to