Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Allow to convert a Struct from Array #91

Merged
merged 7 commits into from
Mar 26, 2019

Conversation

shargon
Copy link
Member

@shargon shargon commented Mar 24, 2019

Closes #51
Closes #88

Allow to convert from Array to Struct and from Struct to array using NEWARRAY and NEWSTRUCT Opcodes


for (var i = 0; i < array.Count; i++)
{
items.Add(array[i]);
Copy link
Contributor

@ixje ixje Mar 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that Struct subclasses Array, I would think the fastest option could be to change the pointer of

protected readonly List<StackItem> _array;

to the equivalent of the new Struct object. The more items the more speed gain. I just don't know if that's possible with C#. Maybe with the unsafe keyword? It just feels bad seeing code looping over items to (almost) only change the type of the class. Just dropping ideas, no C# expert here.

@erikzhang erikzhang merged commit f93ad20 into neo-project:master Mar 26, 2019
@shargon shargon deleted the convert-array-struct branch March 26, 2019 08:43
bors bot added a commit to neo-one-suite/neo-one that referenced this pull request Mar 28, 2019
1256: refactor(PACK+NEWSTRUCT): Replace PACKSTRUCT with PACK+NEWSTRUCT r=dicarlo2 a=afragapane

### Description of the Change
Removes the PACKSTRUCT Opcode and modifies NEWSTRUCT/NEWARRAY to be able to convert an existing array into a struct and struct into array.  This allows the use of a PACK+NEWSTRUCT pair of opcodes in place of PACKSTRUCT.

### Test Plan
Added tests for the conversions in NEWSTRUCT and NEWARRAY.  Updated existing tests to reflect the slightly higher GAS costs of neo-one compiled contracts.

### Alternate Designs
Previously the plan was to implement our PACKSTRUCT in the neo-vm as per neo-project/neo-vm#51 and neo-project/neo-vm#88.  This new solution was suggested and implemented here: neo-project/neo-vm#91.
### Benefits

### Possible Drawbacks
Very slightly higher GAS cost for neo-one compiled smart contracts.  

### Applicable Issues
#1254

Co-authored-by: afragapane <ahfragapane@gmail.com>
bors bot added a commit to neo-one-suite/neo-one that referenced this pull request Mar 28, 2019
1256: refactor(PACK+NEWSTRUCT): Replace PACKSTRUCT with PACK+NEWSTRUCT r=dicarlo2 a=afragapane

### Description of the Change
Removes the PACKSTRUCT Opcode and modifies NEWSTRUCT/NEWARRAY to be able to convert an existing array into a struct and struct into array.  This allows the use of a PACK+NEWSTRUCT pair of opcodes in place of PACKSTRUCT.

### Test Plan
Added tests for the conversions in NEWSTRUCT and NEWARRAY.  Updated existing tests to reflect the slightly higher GAS costs of neo-one compiled contracts.

### Alternate Designs
Previously the plan was to implement our PACKSTRUCT in the neo-vm as per neo-project/neo-vm#51 and neo-project/neo-vm#88.  This new solution was suggested and implemented here: neo-project/neo-vm#91.
### Benefits

### Possible Drawbacks
Very slightly higher GAS cost for neo-one compiled smart contracts.  

### Applicable Issues
#1254

Co-authored-by: afragapane <ahfragapane@gmail.com>
shargon pushed a commit that referenced this pull request Sep 9, 2019
PR #91 implemented ability to convert from Array to Struct and vice
versa.
#91
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants