profile
viewpoint

attaswift/BTree 1202

Fast sorted collections for Swift using in-memory B-trees

attaswift/Attabench 1162

Microbenchmarking app for Swift with nice log-log plots

attaswift/BigInt 607

Arbitrary-precision arithmetic in pure Swift

attaswift/GlueKit 363

Type-safe observable values and collections in Swift

attaswift/SipHash 251

Simple and secure hashing in Swift with the SipHash algorithm

objcio/OptimizingCollections 214

Home of my talk about Optimizing Collections in Swift

attaswift/Deque 65

A double-ended queue type in pure Swift

staggerpkg/stagger 32

An ID3v1/ID3v2 tag manipulation package written in pure Python 3

attaswift/alfred-swift-evolution 29

An Alfred workflow for looking up Swift evolution proposals

numist/Diffing 26

A proposal for adding diffing functionality to the Swift standard library

pull request commentapple/swift-driver

Decode path fields in `InterModuleDependencyGraph` as VirtualPaths

@swift-ci please test

artemcm

comment created time in 14 minutes

PR opened apple/swift-driver

Reviewers
Decode path fields in `InterModuleDependencyGraph` as VirtualPaths

In the process of generating explicit dependency jobs, we end up spending a lot of time constructing VirtualPath objects from strings contained in the dependency graph, (It involves querying whether or not this string constitutes an absolute path, and breaking it down into components) which all add up to a large amount of string manipulation.

Instead, decode these strings into VirtualPath values directly, using the TextualVirtualPath wrapper.

+77 -72

0 comment

8 changed files

pr created time in 14 minutes

push eventapple/swift-driver

Artem Chikin

commit sha f73ef69faa3e48f0ba47ba1de0deab6bb7367021

Display a list of driver modes in batch mode driver help. In the spirit of https://bugs.swift.org/browse/SR-7704, the legacy driver prints out a list of `MODES:` when invoked in "batch-mode": `swiftc --help`. This PR adds the same behaviour here.

view details

Artem Chikin

commit sha fb31a042c1394c125a1ff03d4c26248d4edb1e2e

Merge pull request #436 from artemcm/BatchHelpModes Display a list of driver modes in batch mode driver help.

view details

push time in 17 minutes

PR merged apple/swift-driver

Reviewers
Display a list of driver modes in batch mode driver help.

In the spirit of https://bugs.swift.org/browse/SR-7704, the legacy driver prints out a list of MODES: when invoked in "batch-mode": swiftc --help. This PR adds the same behaviour here.

+22 -2

2 comments

1 changed file

artemcm

pr closed time in 17 minutes

pull request commentapple/swift-driver

Display a list of driver modes in batch mode driver help.

Thanks, @cltnschlosser.

artemcm

comment created time in 17 minutes

startederikzenker/hsm

started time in 20 minutes

pull request commentapple/swift-driver

Display a list of driver modes in batch mode driver help.

@swift-ci please test

artemcm

comment created time in 27 minutes

PR opened apple/swift-driver

Reviewers
Display a list of driver modes in batch mode driver help.

In the spirit of https://bugs.swift.org/browse/SR-7704, the legacy driver prints out a list of MODES: when invoked in "batch-mode": swiftc --help. This PR adds the same behaviour here.

+22 -2

0 comment

1 changed file

pr created time in 27 minutes

startedfrehberg/async-hsm

started time in 38 minutes

startedwebrtc-rs/webrtc

started time in an hour

MemberEvent

PR opened apple/swift-algorithms

Index offsetting for Product2

This PR adds implementations of index(_:offsetBy:) and index(_:offsetBy:limitedBy:) to the Product2 collection. There are ways to further reduce the amount of indices traversed, but this should perform well enough.

LIke Chain2, Product2's index offsetting behavior will now unfortunately perform slightly worse for non-random-access collections in specific scenarios, but there's not much we can do about that.

Checklist

  • [x] I've added at least one test that validates that my change is working, if appropriate
  • [x] I've followed the code style of the rest of the project
  • [x] I've read the Contribution Guidelines
  • [x] I've updated the documentation if necessary
+232 -10

0 comment

1 changed file

pr created time in 2 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// Suffix(while:)+//===----------------------------------------------------------------------===//++extension BidirectionalCollection {+  @inlinable+  public __consuming func Suffix(while predicate: (Element) throws -> Bool+  ) rethrows -> [Element] {+   var result = ContiguousArray<Element>()+   self.reverse()

I don’t believe reverse() can be used here (won’t compile), because it is a mutating function that reverses the elements of the collection in-place. This function, suffix(while:), isn’t mutating (and should remain that way), so it can’t use self.reverse() in its implementation.

It seems that you might have meant to use the non-mutating version of that function, reversed(), which returns a reversed collection:

    for element in self.reversed() {

However, this comment likely won’t be applicable when changing the function to return SubSequence instead.

michiboo

comment created time in 3 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2021 Apple Inc. and the Swift project authors
michiboo

comment created time in 3 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// Suffix(while:)+//===----------------------------------------------------------------------===//++extension BidirectionalCollection {+  @inlinable+  public __consuming func Suffix(while predicate: (Element) throws -> Bool+  ) rethrows -> [Element] {+   var result = ContiguousArray<Element>()+   self.reverse()

Consistent indentation

    var result = ContiguousArray<Element>()
    self.reverse()
michiboo

comment created time in 3 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2021 Apple Inc. and the Swift project authors
michiboo

comment created time in 3 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// Suffix(while:)+//===----------------------------------------------------------------------===//++extension BidirectionalCollection {+  @inlinable+  public __consuming func Suffix(while predicate: (Element) throws -> Bool+  ) rethrows -> [Element] {+   var result = ContiguousArray<Element>()+   self.reverse()+    for element in self {+      guard try predicate(element) else {+        break+      }+      result.append(element)+    }+    result.reverse()+    return Array(result)

This double-reverse operation and converting to Array shouldn’t be necessary. The last index of the collection can be retrieved with endIndex, then walked backwards using index(before:).

This would be similar to the implementation of prefix(while:)<sup>1</sup>, but a little bit trickier. Since endIndex is beyond the subscript-able range of a collection, the index has to be moved backwards before using it to subscript the collection, and ensuring it doesn’t go before the first element (start index). In SuffixTests.swift, I made some comments about test cases that will be important for ensuring that these cases are accounted for.


  1. https://github.com/apple/swift/blob/main/stdlib/public/core/Collection.swift#L1330
michiboo

comment created time in 3 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++import XCTest+import Algorithms++final class SuffixTests: XCTestCase {+  +  func testSuffix() {+    let a = 0...10+    XCTAssertEqualSequences(a.suffix(while: { $0 > 5 }), (6...10))+}
  }
}
michiboo

comment created time in 3 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++import XCTest+import Algorithms++final class SuffixTests: XCTestCase {+  
michiboo

comment created time in 3 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++import XCTest+import Algorithms++final class SuffixTests: XCTestCase {

Tests should be added to handle:

  • Empty input
  • Empty output (predicate doesn’t match the first element)
  • Predicate matches just the first element
  • Predicate matches all elements
michiboo

comment created time in 3 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// Suffix(while:)
// suffix(while:)
michiboo

comment created time in 3 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// Suffix(while:)+//===----------------------------------------------------------------------===//++extension BidirectionalCollection {+  @inlinable

Documentation should be added. Mirroring the documentation for prefix(while:) would be a good start.

michiboo

comment created time in 3 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// Suffix(while:)+//===----------------------------------------------------------------------===//++extension BidirectionalCollection {+  @inlinable+  public __consuming func Suffix(while predicate: (Element) throws -> Bool+  ) rethrows -> [Element] {

Can this return SubSequence instead?

prefix(while:) on Collection returns a SubSequence.<sup>1</sup>


  1. https://github.com/apple/swift/blob/main/stdlib/public/core/Collection.swift#L1328
michiboo

comment created time in 3 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// Suffix(while:)+//===----------------------------------------------------------------------===//++extension BidirectionalCollection {+  @inlinable+  public __consuming func Suffix(while predicate: (Element) throws -> Bool
  public __consuming func suffix(
    while predicate: (Element) throws -> Bool
michiboo

comment created time in 4 hours

Pull request review commentapple/swift-algorithms

add suffix:while method

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// Suffix(while:)+//===----------------------------------------------------------------------===//++extension BidirectionalCollection {+  @inlinable+  public __consuming func Suffix(while predicate: (Element) throws -> Bool
  public __consuming func suffix(while predicate: (Element) throws -> Bool
michiboo

comment created time in 4 hours

pull request commentapple/swift-syntax

Minor internal API improvements

@swift-ci Please test

ahoppen

comment created time in 4 hours

PR opened apple/swift-syntax

Reviewers
Minor internal API improvements

Two minor internal API improvements:

  1. Remove advancedToEndOfChildren These methods are not used anywhere and are potentially incorrect (indexInParent should probably be initialized with raw.numberOfChildren - 1). Remove the until we really need them
  2. Rename advancedBySibling/reversedBySibling to advancedBy/reversedBy We are not actually advancing by a sibling but just by a node, simplify the method name to reflect this.
+10 -29

0 comment

2 changed files

pr created time in 4 hours

PR opened apple/swift-algorithms

add suffix:while method

<!-- Thanks for contributing to Swift Algorithms!

- [x] I've completed this task
- [ ] This task isn't completed

#62

Checklist

  • [ ] I've added at least one test that validates that my change is working, if appropriate
  • [ ] I've followed the code style of the rest of the project
  • [ ] I've read the Contribution Guidelines
  • [ ] I've updated the documentation if necessary
+51 -0

0 comment

2 changed files

pr created time in 5 hours

issue closedapple/swift-algorithms

Permutations won't compile

Bildschirmfoto 2021-01-20 um 08 41 22

The function that was used is unknown on my side ? I use Swift 5.3 and Xcode 12.3, macOS 11.1

closed time in 6 hours

nilsnilsnils
more