Skip to content

Commit bfbc351

Browse files
committed
optimize iteration over dictionary keys
1 parent 59d4d35 commit bfbc351

6 files changed

Lines changed: 19 additions & 19 deletions

File tree

cadence/contracts/FlowYieldVaultsStrategiesV2.cdc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ access(all) contract FlowYieldVaultsStrategiesV2 {
322322
/// Returns the Types of Strategies composed by this StrategyComposer
323323
access(all) view fun getComposedStrategyTypes(): {Type: Bool} {
324324
let composed: {Type: Bool} = {}
325-
for t in self.config.keys {
325+
for t in self.config {
326326
composed[t] = true
327327
}
328328
return composed
@@ -332,7 +332,7 @@ access(all) contract FlowYieldVaultsStrategiesV2 {
332332
access(all) view fun getSupportedInitializationVaults(forStrategy: Type): {Type: Bool} {
333333
let supported: {Type: Bool} = {}
334334
if let strategyConfig = &self.config[forStrategy] as &{Type: FlowYieldVaultsStrategiesV2.CollateralConfig}? {
335-
for collateralType in strategyConfig.keys {
335+
for collateralType in strategyConfig {
336336
supported[collateralType] = true
337337
}
338338
}
@@ -891,7 +891,7 @@ access(all) contract FlowYieldVaultsStrategiesV2 {
891891
}
892892

893893
// Validate keys
894-
for stratType in config.keys {
894+
for stratType in config {
895895
assert(stratType.isSubtype(of: Type<@{FlowYieldVaults.Strategy}>()),
896896
message: "Invalid config key \(stratType.identifier) - not a FlowYieldVaults.Strategy Type")
897897
for collateralType in config[stratType]!.keys {
@@ -904,12 +904,12 @@ access(all) contract FlowYieldVaultsStrategiesV2 {
904904
let existingComposerConfig = self.configs[composer] ?? {}
905905
var mergedComposerConfig = existingComposerConfig
906906

907-
for stratType in config.keys {
907+
for stratType in config {
908908
let newPerCollateral = config[stratType]!
909909
let existingPerCollateral = mergedComposerConfig[stratType] ?? {}
910910
var mergedPerCollateral: {Type: FlowYieldVaultsStrategiesV2.CollateralConfig} = existingPerCollateral
911911

912-
for collateralType in newPerCollateral.keys {
912+
for collateralType in newPerCollateral {
913913
mergedPerCollateral[collateralType] = newPerCollateral[collateralType]!
914914
}
915915
mergedComposerConfig[stratType] = mergedPerCollateral

cadence/contracts/PMStrategiesV1.cdc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ access(all) contract PMStrategiesV1 {
349349

350350
access(all) view fun getComposedStrategyTypes(): {Type: Bool} {
351351
let composed: {Type: Bool} = {}
352-
for t in self.config.keys {
352+
for t in self.config {
353353
composed[t] = true
354354
}
355355
return composed
@@ -593,7 +593,7 @@ access(all) contract PMStrategiesV1 {
593593
"Unsupported StrategyComposer Type \(composer.identifier)"
594594
}
595595
// Validate keys
596-
for stratType in config.keys {
596+
for stratType in config {
597597
assert(stratType.isSubtype(of: Type<@{FlowYieldVaults.Strategy}>()),
598598
message: "Invalid config key \(stratType.identifier) - not a FlowYieldVaults.Strategy Type")
599599
for collateralType in config[stratType]!.keys {
@@ -605,12 +605,12 @@ access(all) contract PMStrategiesV1 {
605605
let existingComposerConfig = self.configs[composer] ?? {}
606606
var mergedComposerConfig: {Type: {Type: {String: AnyStruct}}} = existingComposerConfig
607607

608-
for stratType in config.keys {
608+
for stratType in config {
609609
let newPerCollateral = config[stratType]!
610610
let existingPerCollateral = mergedComposerConfig[stratType] ?? {}
611611
var mergedPerCollateral: {Type: {String: AnyStruct}} = existingPerCollateral
612612

613-
for collateralType in newPerCollateral.keys {
613+
for collateralType in newPerCollateral {
614614
mergedPerCollateral[collateralType] = newPerCollateral[collateralType]!
615615
}
616616
mergedComposerConfig[stratType] = mergedPerCollateral

cadence/contracts/mocks/FlowTransactionScheduler.cdc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,11 +652,11 @@ access(all) contract FlowTransactionScheduler {
652652

653653
var timestampTransactions: {UInt8: [UInt64]} = {}
654654

655-
for priority in transactionPriorities.keys {
655+
for priority in transactionPriorities {
656656
let transactionIDs = transactionPriorities[priority] ?? {}
657657
var priorityTransactions: [UInt64] = []
658658

659-
for id in transactionIDs.keys {
659+
for id in transactionIDs {
660660
priorityTransactions.append(id)
661661
}
662662

@@ -1074,9 +1074,9 @@ access(all) contract FlowTransactionScheduler {
10741074
var medium: [&TransactionData] = []
10751075
var low: [&TransactionData] = []
10761076

1077-
for priority in transactionPriorities.keys {
1077+
for priority in transactionPriorities {
10781078
let transactionIDs = transactionPriorities[priority] ?? {}
1079-
for id in transactionIDs.keys {
1079+
for id in transactionIDs {
10801080
let tx = self.borrowTransaction(id: id)
10811081
if tx == nil {
10821082
emit CriticalIssue(message: "Invalid ID: \(id) transaction not found while preparing pending queue")
@@ -1129,9 +1129,9 @@ access(all) contract FlowTransactionScheduler {
11291129
for timestamp in pastTimestamps {
11301130
let transactionPriorities = self.slotQueue[timestamp] ?? {}
11311131

1132-
for priority in transactionPriorities.keys {
1132+
for priority in transactionPriorities {
11331133
let transactionIDs = transactionPriorities[priority] ?? {}
1134-
for id in transactionIDs.keys {
1134+
for id in transactionIDs {
11351135

11361136
numRemoved = numRemoved + 1
11371137

cadence/contracts/mocks/MockStrategies.cdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ access(all) contract MockStrategies {
139139
var debtCaps: [Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>] = []
140140
var debtPaths: [StoragePath] = []
141141

142-
for debtType in debtsByType.keys {
142+
for debtType in debtsByType {
143143
let debtAmount = debtsByType[debtType]!
144144
let swapper = MockSwapper.Swapper(inVault: ytType, outVault: debtType, uniqueID: self.copyID()!)
145145
let ytAvailable = ytSource.minimumAvailable()
@@ -420,7 +420,7 @@ access(all) contract MockStrategies {
420420
self.getSupportedComposers()[composer] == true:
421421
"Unsupported StrategyComposer Type \(composer.identifier)"
422422
}
423-
for stratType in config.keys {
423+
for stratType in config {
424424
assert(stratType.isSubtype(of: Type<@{FlowYieldVaults.Strategy}>()),
425425
message: "Invalid config key \(stratType.identifier) - not a FlowYieldVaults.Strategy Type")
426426
for collateralType in config[stratType]!.keys {

cadence/scripts/flow-yield-vaults/get_complete_user_position_info.cdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fun main(address: Address): CompleteUserSummary {
207207
var collateralType = "Unknown"
208208
let supportedTypes: [String] = []
209209

210-
for vaultType in supportedVaultTypes.keys {
210+
for vaultType in supportedVaultTypes {
211211
if supportedVaultTypes[vaultType]! {
212212
supportedTypes.append(vaultType.identifier)
213213
if collateralType == "Unknown" {

cadence/tests/test_helpers.cdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ fun setBandOraclePrices(signer: Test.TestAccount, symbolPrices: {String: UFix64}
824824
Test.moveTime(by: 1.0)
825825

826826
let symbolsRates: {String: UInt64} = {}
827-
for symbol in symbolPrices.keys {
827+
for symbol in symbolPrices {
828828
// BandOracle uses 1e9 multiplier for prices
829829
// e.g., $1.00 = 1_000_000_000, $0.50 = 500_000_000
830830
// Split into whole + fractional to avoid UFix64 overflow for large prices (e.g. BTC > $184)

0 commit comments

Comments
 (0)