diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2023-03-22 20:50:57 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2023-03-22 21:05:13 +0000 |
commit | 20f7309220a774e1c2b5b0ec3cf94f4d09c192bd (patch) | |
tree | 9317a30d07e97272940a43ac1e3b5f9d60782f91 /Lib/csharp | |
parent | 5533ca1061c87d019acc04ad1a68ce0f62858c42 (diff) | |
download | swig-20f7309220a774e1c2b5b0ec3cf94f4d09c192bd.tar.gz |
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
Diffstat (limited to 'Lib/csharp')
-rw-r--r-- | Lib/csharp/std_array.i | 22 | ||||
-rw-r--r-- | Lib/csharp/std_vector.i | 6 |
2 files changed, 9 insertions, 19 deletions
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; |