Skip to content

Conversation

MaxGraey
Copy link
Member

@MaxGraey MaxGraey commented Sep 19, 2018

  • add Array#join method;
  • add Array#toString method;
  • add dtoa method;
  • rebase dtoa and itoa to internal/number file;
  • improvements for itoa and add its generic and streaming versions;
  • refactored Array#includes which now reusing Array#indexOf;

DONE

  • Implement dtoa
  • tests for dtoa
  • extra tests for Array#join
  • avoid string concatenation inside Array#join

@MaxGraey MaxGraey changed the title Add Array#join and Array#toString Add Array#join and Array#toString + dtoa Sep 20, 2018
} from "./internal/array";

import { itoa } from "./internal/itoa";
import { dtoa } from "./internal/dtoa";
Copy link
Member

Choose a reason for hiding this comment

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

Could maybe make this internal/number holding all the number compatibility code

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, make sense

Copy link
Member Author

Choose a reason for hiding this comment

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

I think parse<T> should be also move to internal/number. WDYT?

var hasSeparator = separator.length != 0;
if (value instanceof bool) {
for (let i = 0; i < lastIndex; ++i) {
result += loadUnsafe<T,T>(buffer, i) ? "true" : "false";
Copy link
Member

Choose a reason for hiding this comment

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

Without a GC, string concatenation leaves behind unreferenced instances and building the string from scratch using low-level ops might be a better strategy there. Ideally, just the final step, when appending lastIndex, makes a proper string that can be handled by GC.

Copy link
Member Author

Choose a reason for hiding this comment

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

For itoa and especially dtoa this pretty problematic because I don't forecast actual string length produced after stringify and can't preallocate one buffer. But I could allocate one buffer with maximum possible size. WDYT?

Copy link
Member Author

@MaxGraey MaxGraey Sep 24, 2018

Choose a reason for hiding this comment

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

Also this will require two pass (interation through array) logic

@dcodeIO dcodeIO merged commit 53b030f into AssemblyScript:master Oct 1, 2018
@dcodeIO
Copy link
Member

dcodeIO commented Oct 1, 2018

Great, thank you! :)

@MaxGraey MaxGraey deleted the Arrays#toString branch October 1, 2018 21:09
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.

2 participants