From d691f79d78c569016f7861eb6841ae899c5d1503 Mon Sep 17 00:00:00 2001 From: Timothy Zakian Date: Fri, 18 Oct 2024 13:54:06 -0700 Subject: [PATCH] [move] Update some calls to `is_empty` in loops --- .../sui-framework/docs/move-stdlib/vector.md | 4 ++-- .../docs/sui-framework/vec_map.md | 4 ++-- .../docs/sui-framework/vec_set.md | 2 +- .../docs/sui-system/voting_power.md | 2 +- .../packages/move-stdlib/sources/vector.move | 8 ++++---- .../sui-framework/sources/vec_map.move | 4 ++-- .../sui-framework/sources/vec_set.move | 2 +- .../sui-system/sources/voting_power.move | 2 +- .../packages_compiled/move-stdlib | Bin 15569 -> 15601 bytes .../packages_compiled/sui-framework | Bin 66920 -> 66923 bytes .../packages_compiled/sui-system | Bin 44241 -> 44225 bytes crates/sui-protocol-config/src/lib.rs | 1 + 12 files changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/sui-framework/docs/move-stdlib/vector.md b/crates/sui-framework/docs/move-stdlib/vector.md index 0832eebeb7d27..ec746effa9560 100644 --- a/crates/sui-framework/docs/move-stdlib/vector.md +++ b/crates/sui-framework/docs/move-stdlib/vector.md @@ -314,7 +314,7 @@ Pushes all of the elements of the other vector into the lhspublic fun append<Element>(lhs: &mut vector<Element>, mut other: vector<Element>) { other.reverse(); - while (!other.is_empty()) lhs.push_back(other.pop_back()); + while (other.length() != 0) lhs.push_back(other.pop_back()); other.destroy_empty(); } @@ -504,7 +504,7 @@ Aborts if i is out of bounds.
public fun swap_remove<Element>(v: &mut vector<Element>, i: u64): Element {
-    assert!(!v.is_empty(), EINDEX_OUT_OF_BOUNDS);
+    assert!(v.length() != 0, EINDEX_OUT_OF_BOUNDS);
     let last_idx = v.length() - 1;
     v.swap(i, last_idx);
     v.pop_back()
diff --git a/crates/sui-framework/docs/sui-framework/vec_map.md b/crates/sui-framework/docs/sui-framework/vec_map.md
index 96b7c340f3f7f..ec5749359e1c4 100644
--- a/crates/sui-framework/docs/sui-framework/vec_map.md
+++ b/crates/sui-framework/docs/sui-framework/vec_map.md
@@ -262,7 +262,7 @@ Pop the most recently inserted entry from the map. Aborts if the map is empty.
 
 
 
public fun pop<K: copy, V>(self: &mut VecMap<K, V>): (K, V) {
-    assert!(!self.contents.is_empty(), EMapEmpty);
+    assert!(self.contents.length() != 0, EMapEmpty);
     let Entry { key, value } = self.contents.pop_back();
     (key, value)
 }
@@ -526,7 +526,7 @@ and are *not* sorted.
     keys.reverse();
     values.reverse();
     let mut map = empty();
-    while (!keys.is_empty()) map.insert(keys.pop_back(), values.pop_back());
+    while (keys.length() != 0) map.insert(keys.pop_back(), values.pop_back());
     keys.destroy_empty();
     values.destroy_empty();
     map
diff --git a/crates/sui-framework/docs/sui-framework/vec_set.md b/crates/sui-framework/docs/sui-framework/vec_set.md
index 25007f9b3a490..c6ee170d15863 100644
--- a/crates/sui-framework/docs/sui-framework/vec_set.md
+++ b/crates/sui-framework/docs/sui-framework/vec_set.md
@@ -309,7 +309,7 @@ and are *not* sorted.
 
public fun from_keys<K: copy + drop>(mut keys: vector<K>): VecSet<K> {
     keys.reverse();
     let mut set = empty();
-    while (!keys.is_empty()) set.insert(keys.pop_back());
+    while (keys.length() != 0) set.insert(keys.pop_back());
     set
 }
 
diff --git a/crates/sui-framework/docs/sui-system/voting_power.md b/crates/sui-framework/docs/sui-system/voting_power.md index 5b9be689ab2ab..d01fff559824d 100644 --- a/crates/sui-framework/docs/sui-system/voting_power.md +++ b/crates/sui-framework/docs/sui-system/voting_power.md @@ -378,7 +378,7 @@ Update validators with the decided voting power.
fun update_voting_power(validators: &mut vector<Validator>, mut info_list: vector<VotingPowerInfoV2>) {
-    while (!info_list.is_empty()) {
+    while (info_list.length() != 0) {
         let VotingPowerInfoV2 {
             validator_index,
             voting_power,
diff --git a/crates/sui-framework/packages/move-stdlib/sources/vector.move b/crates/sui-framework/packages/move-stdlib/sources/vector.move
index 96a2567855501..e9557b4d3f6ac 100644
--- a/crates/sui-framework/packages/move-stdlib/sources/vector.move
+++ b/crates/sui-framework/packages/move-stdlib/sources/vector.move
@@ -86,7 +86,7 @@ public fun reverse(v: &mut vector) {
 /// Pushes all of the elements of the `other` vector into the `lhs` vector.
 public fun append(lhs: &mut vector, mut other: vector) {
     other.reverse();
-    while (!other.is_empty()) lhs.push_back(other.pop_back());
+    while (other.length() != 0) lhs.push_back(other.pop_back());
     other.destroy_empty();
 }
 
@@ -156,7 +156,7 @@ public fun insert(v: &mut vector, e: Element, mut i: u64) {
 /// This is O(1), but does not preserve ordering of elements in the vector.
 /// Aborts if `i` is out of bounds.
 public fun swap_remove(v: &mut vector, i: u64): Element {
-    assert!(!v.is_empty(), EINDEX_OUT_OF_BOUNDS);
+    assert!(v.length() != 0, EINDEX_OUT_OF_BOUNDS);
     let last_idx = v.length() - 1;
     v.swap(i, last_idx);
     v.pop_back()
@@ -176,7 +176,7 @@ public macro fun tabulate<$T>($n: u64, $f: |u64| -> $T): vector<$T> {
 /// Does not preserve the order of elements in the vector (starts from the end of the vector).
 public macro fun destroy<$T>($v: vector<$T>, $f: |$T|) {
     let mut v = $v;
-    while (!v.is_empty()) $f(v.pop_back());
+    while (v.length() != 0) $f(v.pop_back());
     v.destroy_empty();
 }
 
@@ -185,7 +185,7 @@ public macro fun destroy<$T>($v: vector<$T>, $f: |$T|) {
 public macro fun do<$T>($v: vector<$T>, $f: |$T|) {
     let mut v = $v;
     v.reverse();
-    while (!v.is_empty()) $f(v.pop_back());
+    while (v.length() != 0) $f(v.pop_back());
     v.destroy_empty();
 }
 
diff --git a/crates/sui-framework/packages/sui-framework/sources/vec_map.move b/crates/sui-framework/packages/sui-framework/sources/vec_map.move
index d1fb7646b7e57..6b38d57d289a8 100644
--- a/crates/sui-framework/packages/sui-framework/sources/vec_map.move
+++ b/crates/sui-framework/packages/sui-framework/sources/vec_map.move
@@ -58,7 +58,7 @@ public fun remove(self: &mut VecMap, key: &K): (K, V) {
 
 /// Pop the most recently inserted entry from the map. Aborts if the map is empty.
 public fun pop(self: &mut VecMap): (K, V) {
-    assert!(!self.contents.is_empty(), EMapEmpty);
+    assert!(self.contents.length() != 0, EMapEmpty);
     let Entry { key, value } = self.contents.pop_back();
     (key, value)
 }
@@ -144,7 +144,7 @@ public fun from_keys_values(mut keys: vector, mut values: vector<
     keys.reverse();
     values.reverse();
     let mut map = empty();
-    while (!keys.is_empty()) map.insert(keys.pop_back(), values.pop_back());
+    while (keys.length() != 0) map.insert(keys.pop_back(), values.pop_back());
     keys.destroy_empty();
     values.destroy_empty();
     map
diff --git a/crates/sui-framework/packages/sui-framework/sources/vec_set.move b/crates/sui-framework/packages/sui-framework/sources/vec_set.move
index e4d9301def975..c1b67c276191f 100644
--- a/crates/sui-framework/packages/sui-framework/sources/vec_set.move
+++ b/crates/sui-framework/packages/sui-framework/sources/vec_set.move
@@ -69,7 +69,7 @@ public fun into_keys(self: VecSet): vector {
 public fun from_keys(mut keys: vector): VecSet {
     keys.reverse();
     let mut set = empty();
-    while (!keys.is_empty()) set.insert(keys.pop_back());
+    while (keys.length() != 0) set.insert(keys.pop_back());
     set
 }
 
diff --git a/crates/sui-framework/packages/sui-system/sources/voting_power.move b/crates/sui-framework/packages/sui-system/sources/voting_power.move
index 5a9672316602b..dd0fc336e83f7 100644
--- a/crates/sui-framework/packages/sui-system/sources/voting_power.move
+++ b/crates/sui-framework/packages/sui-system/sources/voting_power.move
@@ -127,7 +127,7 @@ module sui_system::voting_power {
 
     /// Update validators with the decided voting power.
     fun update_voting_power(validators: &mut vector, mut info_list: vector) {
-        while (!info_list.is_empty()) {
+        while (info_list.length() != 0) {
             let VotingPowerInfoV2 {
                 validator_index,
                 voting_power,
diff --git a/crates/sui-framework/packages_compiled/move-stdlib b/crates/sui-framework/packages_compiled/move-stdlib
index 191c7bd74e552887d4ce54cbdffbabd73852fb75..48a182f7e21f30daac43b23a2976615fd5bc6a8e 100644
GIT binary patch
delta 299
zcmY*TyGjE=6uo!u&g|?w@>sJwn;0Yp1T7RqkS$##-(nMlfCvFgF&{7>cA^BV1mpfd
zzCaL5YYVZERCZz_2=R1>^L!r8h7VVA^CG%we`o;!5`hux2gib+48k|OMLD95xFcmI
zbnmBffKj<0y`zgQ=1{>xEn>gu2A0cmTlcY%DcJd^gk1Zv+1hgl>d$UagCR>fR;a+G
zmKAO+_0TYjn&qtgGUowa`m_3OFp~DwPwLmsEsoZj0wJY@GIG>}7OeWC__RTxiXZ~w
zs2CBUnA36=KQUbQ)1;M1&

delta 288
zcmW-by-EW?6ov1dJAauwv&lx?O^nDk@vjg~HDy5ZHbF=urm?aU8>g`oZEYlry``0)
zK1Hw)UqIY=igVyA4&TrGeg1T7_rC4@))#94un2<0RGvC@J~K;vKzl`%ekA9g=_b9{
znPS&Mu1BpUW_iE}8Ahz6SEe5E6uES8xB^?!K|Ly|4+Gdt7u~aU)UE|&nrcR&6GT+o
zwKs88Iczj?J(NZ<0~*|Ak+YYXjH;4@ASaE9gElZZj5@W80{dyFSdbE(G%io-?ecT@
E2ers79RL6T

diff --git a/crates/sui-framework/packages_compiled/sui-framework b/crates/sui-framework/packages_compiled/sui-framework
index 343cb0eaea7cef905a76e8d4903ad910f624e0e8..f7d19e30d1fdbf9aa880a9c35fd5a061e6caf2a0 100644
GIT binary patch
delta 1616
zcmZWpO>7%Q6rOoAyR+WeU3(qdyZ%XHJ5C%Yj$_AdvuTsYPMh>6EzpJ(2?XNCPk{^l
zl@O5-2$4!j)s>KtkN{Pv5*L09h!Ya(1r8L6BjUiH3aCh^g7yL}ym6wmf;oI|=FR)&
zy_tFM{j$oht@8J7A02**KksX=(uc%#`Y|;wv6lWbOPGH#Az$ENy~w`+`%4|1ufp=u
z$xO@wO2BmpB^)Hgzy#aSzy;Fzbg2&pT$==XAS~*THt1w?6nRuLZEBNw2#oON@&b*7
zGspaX6C_$lTM|hFW`P3%=Z0nqT9y#V&WU5s#g^Y4d@FZNsutAI1OS=7-*_^@n%UvVScZ(d#83{d7BBCUKG`17wJ7BYVhRGEeRg
z=O5d*atLohmJ}QYM#w!J;XVzQ_bND|0*Kr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