Skip to content

Comments

修改 contract.json 的 LibString.sol 部分 删去了无用的代码#890

Open
allureluoli wants to merge 2 commits intoWeBankBlockchain:masterfrom
allureluoli:master
Open

修改 contract.json 的 LibString.sol 部分 删去了无用的代码#890
allureluoli wants to merge 2 commits intoWeBankBlockchain:masterfrom
allureluoli:master

Conversation

@allureluoli
Copy link

原代码产生了不必要的内存浪费

function bytesToString(bytes memory _bytes) internal pure returns (string memory){
	_bytes memory bytesArray = new bytes(_bytes.length);
        for (uint256 i; i < _bytes.length; i++) {
            bytesArray[i] = _bytes[i];
        }
        return string(_bytes);
    }

删去了四行已减少内存占用并节省gas费

_bytes memory bytesArray = new bytes(_bytes.length);
    for (uint256 i; i < _bytes.length; i++) {
        bytesArray[i] = _bytes[i];
    }

原代码产生了不必要的内存浪费

```solidity
function bytesToString(bytes memory _bytes) internal pure returns (string memory){
	_bytes memory bytesArray = new bytes(_bytes.length);
        for (uint256 i; i < _bytes.length; i++) {
            bytesArray[i] = _bytes[i];
        }
        return string(_bytes);
    }
```

删去了四行已减少内存占用并节省gas费

```solidity
_bytes memory bytesArray = new bytes(_bytes.length);
    for (uint256 i; i < _bytes.length; i++) {
        bytesArray[i] = _bytes[i];
    }
```
原代码产生了不必要的内存浪费

```solidity
function bytesToString(bytes memory _bytes) internal pure returns (string memory){
	_bytes memory bytesArray = new bytes(_bytes.length);
        for (uint256 i; i < _bytes.length; i++) {
            bytesArray[i] = _bytes[i];
        }
        return string(_bytes);
    }
```

删去了四行已减少内存占用并节省gas费

```solidity
_bytes memory bytesArray = new bytes(_bytes.length);
    for (uint256 i; i < _bytes.length; i++) {
        bytesArray[i] = _bytes[i];
    }
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant