[swift-evolution] Why doesn't removeLast() on Collection return an optional?

Alexis abeingessner at apple.com
Thu Oct 20 10:18:36 CDT 2016


I’m fairly confident the author of the collection has to make those checks for memory-safety, but in theory there’s wins in only doing the check once, and as early as possible. Smaller values to pass, and less checks. 

This is definitely micro-micro-optimization, though. Unlikely to matter for most cases.

> On Oct 18, 2016, at 6:00 PM, Max Moiseev via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Yes, if the author of the collection you’re using performs the check in `removeLast`, but they don’t have to.
> 
>> On Oct 18, 2016, at 1:28 PM, Jean-Daniel <dev at xenonium.com> wrote:
>> 
>> 
>>> Le 17 oct. 2016 à 23:20, Max Moiseev via swift-evolution <swift-evolution at swift.org> a écrit :
>>> 
>>> Hi Louis,
>>> 
>>> I believe, sometimes there are situations where you know for sure that your collection is not empty. Maybe you are already in the context where the check has been performed. In these cases there is no reason you’d have to pay the price of an emptiness check once again.
>> 
>> You have to pay the price anyway, as the check has to be performed to decide if the software should abort.
>> 
>> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161020/880e1aae/attachment.html>


More information about the swift-evolution mailing list