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

Add chop function for chopping iso Strings and Arrays #2337

Merged
merged 1 commit into from
Nov 16, 2017

Conversation

dipinhora
Copy link
Contributor

For context, my main use case for this functionality is efficient buffer manipulations (i.e. minimal or no copying). I had hoped to be able to accomplish this without modifying stdlib but the pointer manipulations required are only possible in builtin.

NOTE: This functionality is not safe until the bugs related to _alloc for String and Array trimming are fixed by #2336.


This commit adds a chop function to both String and Array
that works on an iso and chops it in two with the left half
being a new iso String/Array reusing the same pointer
and the right half being a trim_in_place version of the original
String/Array. Both are returned as iso and mutable and do not
share any memory. The operation does not allocate a new pointer
nor copy elements allowing for efficiency.

@dipinhora
Copy link
Contributor Author

Updated to add chopping an already chopped string to the tests per #2340.

@SeanTAllen
Copy link
Member

@dipinhora During sync we discussed ambiguity about what happens if the split point is outside the string. For example, a string or array of size 5 and a split point of 10. Can you add test(s) for that to demonstrate what happens as well as update the doc-strings to cover what the user should expect?

Other than that, this is looking good to merge.

This commit adds a `chop` function to both String and Array
that works on an `iso` and chops it in two with the left half
being a new `iso` String/Array reusing the same pointer
and the right half being a `trim_in_place` version of the original
String/Array. Both are returned as `iso` and mutable and do not
share any memory. The operation does not allocate a new pointer
nor copy elements allowing for efficiency.
@dipinhora
Copy link
Contributor Author

@SeanTAllen Doh! Thanks to whoever pointed out that edge case.

I've added a case to both String and Array chop tests for that and fixed the logic to work correctly also.

@SeanTAllen
Copy link
Member

@dipinhora I think it was @Praetonus but I don't remember.

@jemc jemc merged commit 9bf0ea9 into ponylang:master Nov 16, 2017
ponylang-main added a commit that referenced this pull request Nov 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - added Automatically add "Added" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants