Skip to content

Added NSArray.replaceObjectsInRange(range, otherArray, otherRange) #139

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

Merged
merged 2 commits into from
Dec 18, 2015

Conversation

terhechte
Copy link
Contributor

Added the implementation of this method as well as a test for it

@terhechte terhechte changed the title Added NSArray.replaceObjectsInRange(range, otherArray, otherRange) Added the implementation of this method as well as a test for it Added NSArray.replaceObjectsInRange(range, otherArray, otherRange) Dec 13, 2015
@joshuatbrown
Copy link
Contributor

There are now three implementations of this method:

  1. PR NSMutableArray replaceObjectsInRange:withObjectsFromArray:range: #125
  2. PR [NSMutableArray] replace objects in range docs/tests/impl #136
  3. PR Added NSArray.replaceObjectsInRange(range, otherArray, otherRange)  #139 (this one)

Not sure which should be merged, but I'm guessing not all of them should be. :)

@parkera
Copy link
Contributor

parkera commented Dec 16, 2015

We'll try to get this sorted out...

@terhechte
Copy link
Contributor Author

Oops sorry! I hadn't seen these other PRs. I'll do a better search next time.
Interestingly we're all using slightly different implementations:

self.replaceObjectsInRange(range, withObjectsFromArray: Array(otherArray[otherRange.toRange()!]))

vs

let slicedOtherArray = Array(otherArray[otherRange.location...otherRange.length+otherRange.location]) replaceObjectsInRange(range, withObjectsFromArray: slicedOtherArray)

vs

replaceObjectsInRange(range, withObjectsFromArray: otherArray.bridge().subarrayWithRange(otherRange))

@phausler
Copy link
Contributor

so the expected call pattern in objc is:

[array getObjects:list range:otherRange];
[self replaceObjectsInRange:range withObjects:list count:otherRange.length];

this should probably hit the same type of call pattern:

var list = [AnyObject]()
array.getObjects(&list, range:otherRange)
replaceObjectsInRange(range, withObjectsFromArray:list)

this preserves subclasser expectations for performance since getObjects:range: should be the method to override as a "fast path"

@phausler
Copy link
Contributor

merged in for extra unit tests

atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
…lchain

 [sourcekit-lsp] Prefer containing toolchain if applicable
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.

4 participants