Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Cleanup offset constants in String module #2237

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

spotandjake
Copy link
Member

This pr works towards #703 I started with the string module, I also changed a few other modules to use the common offsets module for their offsets, if we are good with the approach I am taking to this I will do the same to the other modules but I figure that might be best todo in a separate pr.

Notes:

  • I found some other utf-8 cleanup that I threw into this pr as it wasn't much.
  • I also made the other modules with offsets already defined in variables point to the Offsets module for consistency sake.

stdlib/runtime/unsafe/offsets.gr Outdated Show resolved Hide resolved
* @returns `true` if the byte is a leading byte, `false` otherwise
*/
@unsafe
provide let isLeadingByte = byte => {
Copy link
Member

Choose a reason for hiding this comment

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

Was this intended to be used somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is used in string.gr so its just a tiny bit of cleanup I noticed while looking for constants and decided to address in this pr.

WasmI32.store(arr + arrIdx, str, 8n)
arrIdx += 4n
Memory.copy(str + _STR_DATA_OFFSET, last, strSize)
WasmI32.store(arr + _ARRAY_DATA_OFFSET, str, arrIdx)
Copy link
Member

Choose a reason for hiding this comment

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

Why did you flip these

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 flipped them as I figured we should be offsetting into the array for the item rather than moving the pointer, it doesn't really make a difference though.

let str = " argument must be non-negative"
throw Exception.InvalidArgument(name ++ str)
use WasmI32.{ (<) }
let _num = convSimpleNumber(num, name ++ " argument must be an integer")
Copy link
Member

Choose a reason for hiding this comment

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

A note is that in the nominal case this is now less efficient due to needing to do this string allocation + concat every time rather than only in the bad case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants