Skip to content

[Implement] subarray - #20

Merged
jtenner merged 2 commits into
masterfrom
subarray
Aug 1, 2019
Merged

[Implement] subarray#20
jtenner merged 2 commits into
masterfrom
subarray

Conversation

@jtenner

@jtenner jtenner commented Jul 29, 2019

Copy link
Copy Markdown
Contributor

Original .subarray() implementation does not return Buffer. It returns Uint8Array.

Copied and optimized for our purposes from the SUBARRAY macro. Any problems? @dcodeIO

@jtenner
jtenner requested a review from dcodeIO July 29, 2019 17:05
@dcodeIO

dcodeIO commented Jul 29, 2019

Copy link
Copy Markdown
Member

Can this maybe reuse the Uint8Array implementation, like in changetype<Buffer>(super.subarray(...))? Edit: Hmm, no, the id wouldn't match.

@jtenner

jtenner commented Jul 29, 2019

Copy link
Copy Markdown
Contributor Author

@dcodeIO We could reuse the parent class's version. All we have to do is change the rtId value.

let result = super.subarray(...);
let block = changetype<BLOCK>(changetype<usize>(result) - BLOCK_OFFSET); // whatever this is
block.rtId = idOf<Buffer>();
return result;

@jtenner

jtenner commented Jul 29, 2019

Copy link
Copy Markdown
Contributor Author

Best solution would just be to use the macro in the std lib but it's not exported.

@jtenner

jtenner commented Aug 1, 2019

Copy link
Copy Markdown
Contributor Author

Unless there are any problems with this implementation, can we pull this?

@jtenner

jtenner commented Aug 1, 2019

Copy link
Copy Markdown
Contributor Author

I will leave this as implemented for now because it's technically faster than:

let out = super.subarray(start, end);
changetype<BLOCK>(changetype<usize>(out) - BLOCK_OFFSET).rtId = idof<Buffer>();
return out;

@MaxGraey

MaxGraey commented Aug 1, 2019

Copy link
Copy Markdown
Member

How about use:

public subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Buffer {
  return SUBARRAY<Buffer, u8>(this, begin, end);
}

And make SUBARRAY macro from typedarray.ts exportable.

@MaxGraey

MaxGraey commented Aug 1, 2019

Copy link
Copy Markdown
Member

Or even better move all typedarray's macros to new std/assembly/util/typedarray.ts file

@jtenner

jtenner commented Aug 1, 2019

Copy link
Copy Markdown
Contributor Author

@MaxGraey That would be nice, but I can't use the SUBARRAY function unless it's exported by the std library. Will have to wait until that changes.

@dcodeIO

dcodeIO commented Aug 1, 2019

Copy link
Copy Markdown
Member

Seems fine this way.

@jtenner

jtenner commented Aug 1, 2019

Copy link
Copy Markdown
Contributor Author

If AssemblyScript/assemblyscript#740 pulls, then I will refactor the current implementation to contain the utility functions.

@dcodeIO
dcodeIO deleted the subarray branch June 1, 2021 15:32
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.

3 participants