From 20f7309220a774e1c2b5b0ec3cf94f4d09c192bd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 22 Mar 2023 20:50:57 +0000 Subject: std_array.i std_vector.i tweaks Efficiency fixes and tidy up from previous commit. Add test case for constructing from differently sized containers. Issue #2478 --- Lib/csharp/std_array.i | 22 ++++++---------------- Lib/csharp/std_vector.i | 6 +++--- 2 files changed, 9 insertions(+), 19 deletions(-) (limited to 'Lib') diff --git a/Lib/csharp/std_array.i b/Lib/csharp/std_array.i index 681ec7a2a..87b1b8956 100644 --- a/Lib/csharp/std_array.i +++ b/Lib/csharp/std_array.i @@ -15,20 +15,10 @@ public $csclassname(global::System.Collections.ICollection c) : this() { if (c == null) throw new global::System.ArgumentNullException("c"); + int count = this.Count; int i = 0; foreach ($typemap(cstype, CTYPE) element in c) { - if (i >= this.Count) - break; - this[i++] = element; - } - } - - public $csclassname(global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)> c) : this() { - if (c == null) - throw new global::System.ArgumentNullException("c"); - int i = 0; - foreach ($typemap(cstype, CTYPE) element in c) { - if (i >= this.Count) + if (i >= count) break; this[i++] = element; } @@ -57,7 +47,7 @@ public bool IsEmpty { get { - return (size() == 0); + return empty(); } } @@ -195,6 +185,9 @@ typedef value_type& reference; typedef const value_type& const_reference; + array(); + array(const array &other); + size_type size() const; bool empty() const; @@ -204,9 +197,6 @@ %rename(Swap) swap; void swap(array& other); - array(); - array(const array &other); - %extend { CTYPE getitemcopy(int index) throw (std::out_of_range) { if (index>=0 && index<(int)$self->size()) diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index 142404194..8438f6418 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -209,6 +209,9 @@ typedef value_type& reference; typedef CONST_REFERENCE const_reference; + vector(); + vector(const vector &other); + %rename(Clear) clear; void clear(); %rename(Add) push_back; @@ -220,9 +223,6 @@ %newobject GetRange(int index, int count); %newobject Repeat(CTYPE const& value, int count); - vector(); - vector(const vector &other); - %extend { vector(int capacity) throw (std::out_of_range) { std::vector< CTYPE >* pv = 0; -- cgit v1.2.1