aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-07-18 07:58:00 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-07-23 23:00:23 +0800
commit4636d5fbc2ad3350278dc9fa2e780c2afa08d3d9 (patch)
treecb5b73b17cd8da071df2e34a8b43769a4b95b0fa /packages
parent3506ec1caa2a6c7ee2d68970553ca53d8ceb5c64 (diff)
downloaddexon-sol-tools-4636d5fbc2ad3350278dc9fa2e780c2afa08d3d9.tar
dexon-sol-tools-4636d5fbc2ad3350278dc9fa2e780c2afa08d3d9.tar.gz
dexon-sol-tools-4636d5fbc2ad3350278dc9fa2e780c2afa08d3d9.tar.bz2
dexon-sol-tools-4636d5fbc2ad3350278dc9fa2e780c2afa08d3d9.tar.lz
dexon-sol-tools-4636d5fbc2ad3350278dc9fa2e780c2afa08d3d9.tar.xz
dexon-sol-tools-4636d5fbc2ad3350278dc9fa2e780c2afa08d3d9.tar.zst
dexon-sol-tools-4636d5fbc2ad3350278dc9fa2e780c2afa08d3d9.zip
Store orders length in varible before looping over orders
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinForwarderCore.sol9
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol30
2 files changed, 25 insertions, 14 deletions
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinForwarderCore.sol b/packages/contracts/src/2.0.0/forwarder/MixinForwarderCore.sol
index 9dc203373..561507ce4 100644
--- a/packages/contracts/src/2.0.0/forwarder/MixinForwarderCore.sol
+++ b/packages/contracts/src/2.0.0/forwarder/MixinForwarderCore.sol
@@ -245,7 +245,8 @@ contract MixinForwarderCore is
orders[0].takerAssetData = WETH_ASSET_DATA;
// All orders are required to have the same makerAssetData. We save on gas by reusing the makerAssetData of the first order.
- for (uint256 i = 0; i < orders.length; i++) {
+ uint256 ordersLength = orders.length;
+ for (uint256 i = 0; i < ordersLength; i++) {
orders[i].makerAssetData = orders[0].makerAssetData;
}
@@ -274,7 +275,8 @@ contract MixinForwarderCore is
bytes memory wethAssetData = WETH_ASSET_DATA;
// All orders are required to have WETH as takerAssetData. We save on gas by populating the orders here, rather than passing in any extra calldata.
- for (uint256 i = 0; i < orders.length; i++) {
+ uint256 ordersLength = orders.length;
+ for (uint256 i = 0; i < ordersLength; i++) {
orders[i].takerAssetData = wethAssetData;
}
@@ -311,7 +313,8 @@ contract MixinForwarderCore is
bytes memory wethAssetData = WETH_ASSET_DATA;
uint256 zrxPurchased = 0;
- for (uint256 i = 0; i < orders.length; i++) {
+ uint256 ordersLength = orders.length;
+ for (uint256 i = 0; i < ordersLength; i++) {
// All of these are ZRX/WETH, so we can drop the respective assetData from calldata.
orders[i].makerAssetData = zrxAssetData;
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol
index 0abf53d02..adb56799a 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol
@@ -119,7 +119,8 @@ contract MixinWrapperFunctions is
public
returns (FillResults memory totalFillResults)
{
- for (uint256 i = 0; i < orders.length; i++) {
+ uint256 ordersLength = orders.length;
+ for (uint256 i = 0; i < ordersLength; i++) {
FillResults memory singleFillResults = fillOrder(
orders[i],
takerAssetFillAmounts[i],
@@ -144,7 +145,8 @@ contract MixinWrapperFunctions is
public
returns (FillResults memory totalFillResults)
{
- for (uint256 i = 0; i < orders.length; i++) {
+ uint256 ordersLength = orders.length;
+ for (uint256 i = 0; i < ordersLength; i++) {
FillResults memory singleFillResults = fillOrKillOrder(
orders[i],
takerAssetFillAmounts[i],
@@ -170,7 +172,8 @@ contract MixinWrapperFunctions is
public
returns (FillResults memory totalFillResults)
{
- for (uint256 i = 0; i < orders.length; i++) {
+ uint256 ordersLength = orders.length;
+ for (uint256 i = 0; i < ordersLength; i++) {
FillResults memory singleFillResults = fillOrderNoThrow(
orders[i],
takerAssetFillAmounts[i],
@@ -196,7 +199,8 @@ contract MixinWrapperFunctions is
{
bytes memory takerAssetData = orders[0].takerAssetData;
- for (uint256 i = 0; i < orders.length; i++) {
+ uint256 ordersLength = orders.length;
+ for (uint256 i = 0; i < ordersLength; i++) {
// We assume that asset being sold by taker is the same for each order.
// Rather than passing this in as calldata, we use the takerAssetData from the first order in all later orders.
@@ -239,7 +243,8 @@ contract MixinWrapperFunctions is
{
bytes memory takerAssetData = orders[0].takerAssetData;
- for (uint256 i = 0; i < orders.length; i++) {
+ uint256 ordersLength = orders.length;
+ for (uint256 i = 0; i < ordersLength; i++) {
// We assume that asset being sold by taker is the same for each order.
// Rather than passing this in as calldata, we use the takerAssetData from the first order in all later orders.
@@ -281,7 +286,8 @@ contract MixinWrapperFunctions is
{
bytes memory makerAssetData = orders[0].makerAssetData;
- for (uint256 i = 0; i < orders.length; i++) {
+ uint256 ordersLength = orders.length;
+ for (uint256 i = 0; i < ordersLength; i++) {
// We assume that asset being bought by taker is the same for each order.
// Rather than passing this in as calldata, we copy the makerAssetData from the first order onto all later orders.
@@ -332,7 +338,8 @@ contract MixinWrapperFunctions is
{
bytes memory makerAssetData = orders[0].makerAssetData;
- for (uint256 i = 0; i < orders.length; i++) {
+ uint256 ordersLength = orders.length;
+ for (uint256 i = 0; i < ordersLength; i++) {
// We assume that asset being bought by taker is the same for each order.
// Rather than passing this in as calldata, we copy the makerAssetData from the first order onto all later orders.
@@ -372,7 +379,8 @@ contract MixinWrapperFunctions is
function batchCancelOrders(LibOrder.Order[] memory orders)
public
{
- for (uint256 i = 0; i < orders.length; i++) {
+ uint256 ordersLength = orders.length;
+ for (uint256 i = 0; i < ordersLength; i++) {
cancelOrder(orders[i]);
}
}
@@ -385,9 +393,9 @@ contract MixinWrapperFunctions is
view
returns (LibOrder.OrderInfo[] memory)
{
- uint256 length = orders.length;
- LibOrder.OrderInfo[] memory ordersInfo = new LibOrder.OrderInfo[](length);
- for (uint256 i = 0; i < length; i++) {
+ uint256 ordersLength = orders.length;
+ LibOrder.OrderInfo[] memory ordersInfo = new LibOrder.OrderInfo[](ordersLength);
+ for (uint256 i = 0; i < ordersLength; i++) {
ordersInfo[i] = getOrderInfo(orders[i]);
}
return ordersInfo;