Skip to content

[Implement] subarray#20

Merged
jtenner merged 2 commits intomasterfrom
subarray
Aug 1, 2019
Merged

[Implement] subarray#20
jtenner merged 2 commits intomasterfrom
subarray

Conversation

@jtenner
Copy link
Copy Markdown
Contributor

@jtenner jtenner commented Jul 29, 2019

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
Copy link
Copy Markdown
Member

dcodeIO commented Jul 29, 2019

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

@jtenner
Copy link
Copy Markdown
Contributor Author

jtenner commented Jul 29, 2019

@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
Copy link
Copy Markdown
Contributor Author

jtenner commented Jul 29, 2019

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

@jtenner
Copy link
Copy Markdown
Contributor Author

jtenner commented Aug 1, 2019

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

@jtenner
Copy link
Copy Markdown
Contributor Author

jtenner commented Aug 1, 2019

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
Copy link
Copy Markdown
Member

MaxGraey commented Aug 1, 2019

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
Copy link
Copy Markdown
Member

MaxGraey commented Aug 1, 2019

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

@jtenner
Copy link
Copy Markdown
Contributor Author

jtenner commented Aug 1, 2019

@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
Copy link
Copy Markdown
Member

dcodeIO commented Aug 1, 2019

Seems fine this way.

@jtenner
Copy link
Copy Markdown
Contributor Author

jtenner commented Aug 1, 2019

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