<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 10, 2017 at 1:00 AM, Xiaodi Wu <span dir="ltr"><<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><div><div><div><div><div><div class="gmail_quote"><div dir="auto">On Mon, Oct 9, 2017 at 19:47 Kelvin Ma via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div>Hi guys, after passing <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0184-unsafe-pointers-add-missing.md" target="_blank">SE 184 (A)</a>, I want to get some community feedback on the next phase of our Swift pointer overhaul which is a partial initialization/<wbr>deinitialization API for <span style="font-family:monospace,monospace">UnsafeMutableBufferPointer</span> and <span style="font-family:monospace,monospace">UnsafeMutableRawBufferPointer</span>. <br><br></div>You can read about the originally proposed API in the <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0184-unsafe-pointers-add-missing.md" target="_blank">original SE 184 document</a>, basically we use an <span style="font-family:monospace,monospace">at:from:</span> system for binary memory state operations where the <span style="font-family:monospace,monospace">at:</span> argument supplies the start position in the destination buffer, and the <span style="font-family:monospace,monospace">from:</span> source argument supplies the number of elements to copy/move into the destination. <br></div><br><span style="font-family:monospace,monospace">newBuffer.moveInitialize(at: 0, from: self.buffer[self.zero... ])<br>newBuffer.moveInitialize(at: self.zero, from: self.buffer[0 ..< self.zero])<br></span><div><br></div>Some other proposed APIs include using subscript notation, and writing a special buffer slice type and a corresponding protocol to handle this. <br><br><span style="font-family:monospace,monospace">newBuffer[0... ].moveInitialize(from: self.buffer[self.zero... ])<br>newBuffer[self.zero ... self.zero << 1].moveInitialize(from: self.buffer[0 ..< self.zero])</span><br></div></blockquote><div dir="auto"><br></div></div></div></div></div></div></div></span><div><div><div><div><div><div class="gmail_quote"><div dir="auto">Fully embracing slice notation and SwiftLint style, this could be:</div><div dir="auto"><br></div><div dir="auto">newBuffer[...].moveInitialize(<wbr>from: buffer[zero...])</div><div dir="auto">newBuffer[zero...].<wbr>moveInitialize(from: buffer[..<zero])</div></div></div></div></div></div></div></blockquote><div><br></div><div>Is the solo ellipsis operator even valid Swift syntax? And I agree this would look nice, but as others have mentioned, Swift has the convention that the one-sided slice operators are equivalent to <span style="font-family:monospace,monospace">start ... endIndex</span> and <span style="font-family:monospace,monospace">startIndex ... end</span>. And that seems to strongly suggest that the method would initialize the entire range which is not what we want to communicate.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div><div class="gmail_quote"></div></div></div></div><span class=""><div><div><div><div class="gmail_quote"><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>A hypothetical comparison of this API, the <span style="font-family:monospace,monospace">at:from:</span> API, and the existing plain pointer API can be found in this basic Swift queue implementation <a href="https://gist.github.com/kelvin13/0860334278aeab5c1cbaefbefb050268" target="_blank">here</a> if anyone wants to see how this would look in “real” code. I’m interested in seeing which syntax and which API is preferred as well as what people would like to do with an expanded Swift buffer pointer toolbox.</div></blockquote><div dir="auto"><br></div></div></div></div></div></span><div><div><div><div class="gmail_quote"><div dir="auto">Would you mind rewriting these examples in a more common Swift style (for instance, SwiftLint/GitHub style)? Everyone is entitled to write code how they please, but it’s much easier to compare how things “look” when the overall formatting is more familiar. <br></div></div></div></div></div></blockquote><div><br></div><div>I mean the purpose of the example is to compare the call sites of the actual buffer methods. ignoring the function signatures and instead getting distracted by brace placement seems like the kind of bikeshedding we should be discouraging lol.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div><div class="gmail_quote"><div dir="auto"></div></div></div></div></div><div><div><div><div class="gmail_quote"><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br></div>
______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
</blockquote></div></div></div></div>
</blockquote></div><br></div></div>