Re: [swift-users] Why are Swift Loops slow?

2016-10-12 Thread Gerriet M. Denkmann via swift-users
> On 12 Oct 2016, at 23:05, Joe Groff via swift-users > wrote: > >> >> On Oct 12, 2016, at 2:25 AM, Gerriet M. Denkmann via swift-users >> wrote: >> >> uint64_t nbrBytes = 4e8; >> uint64_t count = 0; >> for( uint64_t byteIndex = 0; byteIndex < nbrBytes; byteIndex++ ) >> { >> count += b

Re: [swift-users] How to be DRY on ranges and closed ranges?

2016-10-12 Thread Hooman Mehr via swift-users
> On Oct 12, 2016, at 3:21 AM, Jean-Denis Muys via swift-users > wrote: > > > But this is not very DRY. > > What would be a more idiomatic way? > The more idiomatic way is to look at API design in a new way. Note these points: 1. `Countable` variant is preferred when you want to deal with

[swift-users] Installation permissions issue with 3.0 release in Ubuntu 14.04?

2016-10-12 Thread Owen Smith via swift-users
Greetings, I'm not sure where to take this issue, so I'm starting here. It's an installation issue, not a language issue. Any tips on where to send this would be greatly appreciated! (And of course please let me know if it's a known issue.) I'm one of the brave that is installing Swift 3.0 on Ubu

Re: [swift-users] Counting in Threads

2016-10-12 Thread Daniel Dunbar via swift-users
Not in this case, today: -- $ cat x.swift import Darwin.C public class AtomicInt32 { public fileprivate (set) var value : Int32 = 0 /// Create a new atomic integer with the specified initial value. public init(_ value: Int32 = 0) { self.value = value } /// Add one to the v

Re: [swift-users] How to be DRY on ranges and closed ranges?

2016-10-12 Thread Jenus Dong via swift-users
Yes, it is so inconvenient to use that CloseRange isn’t the special of Range. But according to your case, CountableRange can be used in the condition. And ClosedCountableRange and CountableRange is available to converting. Refer: https://oleb.net/blog/2016/09/swift-3-ranges/

Re: [swift-users] Counting in Threads

2016-10-12 Thread Philippe Hausler via swift-users
Or allocate a pointer for it. The other alternative would be NSLock but that might be swatting flies with sledgehammers. We had a similar issue implementing NSLock in swift-corelibs-foundation where taking the address of a pthread mutex corrupted the structure for when another thread would attem

[swift-users] Build Android GUI apps with Swift 3.0 via a framework/library

2016-10-12 Thread Tony Constantinides via swift-users
In Swift 3.0 you can build Android apps in Linux but only console apps as there is no framework to build GUI apps using JNI. What I propose is to build an initial limited framework coded in C that calls enough of the Java Android API via JNI to bootstrap the android app and to create widgets and la

Re: [swift-users] How to be DRY on ranges and closed ranges?

2016-10-12 Thread Nevin Brackett-Rozinsky via swift-users
You could also create a “Range” protocol with “lowerBound” and “upperBound” properties. Conform all the range types to it, and make your function take generic over the protocol. Nevin On Wed, Oct 12, 2016 at 7:21 PM, Hooman Mehr via swift-users < swift-users@swift.org> wrote: > I recommend havi

Re: [swift-users] Counting in Threads

2016-10-12 Thread Shawn Erickson via swift-users
So we would have to drop down to C code, etc. to safely leverage OSAtomic? On Wed, Oct 12, 2016 at 8:32 AM Philippe Hausler via swift-users < swift-users@swift.org> wrote: > I was under the impression that taking the address was more than a single > load instruction and would emit a placeholder i

Re: [swift-users] How to be DRY on ranges and closed ranges?

2016-10-12 Thread Hooman Mehr via swift-users
I recommend having explicit precondition and reducing repetition like this: import Foundation func random(from range: CountableRange) -> Int { precondition(range.count > 0, "The range can't be empty.") return random(from: CountableClosedRange(range)) } func random(

Re: [swift-users] Why are Swift Loops slow?

2016-10-12 Thread Andrew Trick via swift-users
> On Oct 12, 2016, at 9:05 AM, Joe Groff via swift-users > wrote: > > It looks like LLVM does not recognize the overflow traps Swift emits on > arithmetic operations as dead code, so that prevents it from completely > eliminating the Swift loop. That's a bug worth fixing in Swift, but unlike

Re: [swift-users] How to be DRY on ranges and closed ranges?

2016-10-12 Thread Adriano Ferreira via swift-users
Hi there! Ole Begeman offers here (take a look at the bottom of the page) an interesting consideration about converting between half-open and closed ranges. As of now, it seems the way to go is by overloading… import Foundation func random(from

Re: [swift-users] Segfault only when running swift in system-wide directory

2016-10-12 Thread mishal_shah via swift-users
Thanks Lane! > On Oct 12, 2016, at 11:11 AM, Lane Schwartz wrote: > > Done: https://bugs.swift.org/browse/SR-2929 > > > On Mon, Oct 10, 2016 at 1:28 PM, mishal_shah > wrote: > Hi Lane, > > Can you please file a bug on bug

Re: [swift-users] Segfault only when running swift in system-wide directory

2016-10-12 Thread Lane Schwartz via swift-users
Done: https://bugs.swift.org/browse/SR-2929 On Mon, Oct 10, 2016 at 1:28 PM, mishal_shah wrote: > Hi Lane, > > Can you please file a bug on bugs.swift.org? > > Thanks, > Mishal Shah > > On Oct 9, 2016, at 11:56 AM, Lane Schwartz via swift-users < > swift-users@swift.org> wrote: > > > > Hi, > > >

Re: [swift-users] Why are Swift Loops slow?

2016-10-12 Thread Joe Groff via swift-users
> On Oct 12, 2016, at 2:25 AM, Gerriet M. Denkmann via swift-users > wrote: > > uint64_t nbrBytes = 4e8; > uint64_t count = 0; > for( uint64_t byteIndex = 0; byteIndex < nbrBytes; byteIndex++ ) > { > count += byteIndex; > if ( ( byteIndex & 0x ) == 0 ) { count += 1.3; } (AA

Re: [swift-users] find std lib doc

2016-10-12 Thread David Hart via swift-users
Dash + Alfred :) > On 12 Oct 2016, at 17:13, Lars-Jørgen Kristiansen via swift-users > wrote: > > I recommend Dash 😏 > >> 12. okt. 2016 kl. 17.03 skrev Adrian Zubarev via swift-users >> mailto:swift-users@swift.org>>: >> >> You could also fallback to http://swiftdoc.org

Re: [swift-users] Counting in Threads

2016-10-12 Thread Philippe Hausler via swift-users
I was under the impression that taking the address was more than a single load instruction and would emit a placeholder invalid value: which would make that technically unsafe in a threaded context. Sent from my iPhone > On Oct 12, 2016, at 8:18 AM, Daniel Dunbar via swift-users > wrote: > >

Re: [swift-users] Counting in Threads

2016-10-12 Thread Daniel Dunbar via swift-users
I suspect one of the actual compiler people might tell me I shouldn't trust this, but in practice it works: -- import Darwin.C public class AtomicInt32 { public fileprivate (set) var value : Int32 = 0 /// Create a new atomic integer with the specified initial value. public init(_

Re: [swift-users] find std lib doc

2016-10-12 Thread Lars-Jørgen Kristiansen via swift-users
I recommend Dash 😏 > 12. okt. 2016 kl. 17.03 skrev Adrian Zubarev via swift-users > : > > You could also fallback to http://swiftdoc.org . ;) > > > > > -- > Adrian Zubarev > Sent with Airmail > > Am 12. Oktober 2016 um 17:01:48, Jon Shier via swift-users > (swift-use

Re: [swift-users] find std lib doc

2016-10-12 Thread Adrian Zubarev via swift-users
You could also fallback to http://swiftdoc.org. ;) --  Adrian Zubarev Sent with Airmail Am 12. Oktober 2016 um 17:01:48, Jon Shier via swift-users (swift-users@swift.org) schrieb: I’m guessing you only came to Apple’s developer environment with Swift? (If not I apologize.) The searchability

Re: [swift-users] find std lib doc

2016-10-12 Thread Jon Shier via swift-users
I’m guessing you only came to Apple’s developer environment with Swift? (If not I apologize.) The searchability and discoverability of anything on Apple’s dev site is rather low. You learn to live with it and use Google whenever you need to find something. (Which turns up the standard li

Re: [swift-users] How to be DRY on ranges and closed ranges?

2016-10-12 Thread David Hart via swift-users
I’ve been bitten by that quite a few times. I’m not a fan of the new distinction between Range and ClosedRange. I understand the reasoning behind them, but the new model is creating more problems for me than the it solves. David. > On 12 Oct 2016, at 12:21, Jean-Denis Muys via swift-users > w

Re: [swift-users] find std lib doc

2016-10-12 Thread J.E. Schotsman via swift-users
> On 12 Oct 2016, at 13:31, Adrian Zubarev > wrote: > > It’s not hidden. > > https://developer.apple.com/ > Develop > API Reference > Swift Standard Library > Profit https://developer.apple.com/reference/swift > I see

Re: [swift-users] find std lib doc

2016-10-12 Thread Adrian Zubarev via swift-users
It’s not hidden. https://developer.apple.com/ Develop API Reference Swift Standard Library Profit https://developer.apple.com/reference/swift --  Adrian Zubarev Sent with Airmail Am 12. Oktober 2016 um 11:55:17, J.E. Schotsman via swift-users (swift-users@swift.org) schrieb: Is it just me, o

[swift-users] How to be DRY on ranges and closed ranges?

2016-10-12 Thread Jean-Denis Muys via swift-users
Hi, I defined this: func random(from r: Range) -> Int { let from = r.lowerBound let to = r.upperBound let rnd = arc4random_uniform(UInt32(to-from)) return from + Int(rnd) } so that I can do: let testRandomValue = random(from: 4..<8) But this will not let me do: let other

Re: [swift-users] Why are Swift Loops slow?

2016-10-12 Thread Greg Parker via swift-users
> On Oct 12, 2016, at 2:25 AM, Gerriet M. Denkmann via swift-users > wrote: > > uint64_t nbrBytes = 4e8; > uint64_t count = 0; > for( uint64_t byteIndex = 0; byteIndex < nbrBytes; byteIndex++ ) > { > count += byteIndex; > if ( ( byteIndex & 0x ) == 0 ) { count += 1.3; } (AA

[swift-users] find std lib doc

2016-10-12 Thread J.E. Schotsman via swift-users
Is it just me, or is the Standard library document not very discoverable? Try searching developer.apple.com for "(Swift) standard library". No hit! Can’t find it on swift.org either (which isn’t even searchable). In case anybody else needs it, Mateusz Malczak gave me the link: https://developer.a

[swift-users] Why are Swift Loops slow?

2016-10-12 Thread Gerriet M. Denkmann via swift-users
uint64_t nbrBytes = 4e8; uint64_t count = 0; for( uint64_t byteIndex = 0; byteIndex < nbrBytes; byteIndex++ ) { count += byteIndex; if ( ( byteIndex & 0x ) == 0 ) { count += 1.3; } (AAA) }; Takes 260 msec. Btw.: Without the (AAA) line the whole loop is done in 10 μsec. A

[swift-users] Counting in Threads

2016-10-12 Thread Gerriet M. Denkmann via swift-users
How to translate this to Swift: __block atomic_uint_fast64_t counter = ATOMIC_VAR_INIT(0); dispatch_apply( nbrInterations, queue, ^void(size_t idx) { uint64_t tCount = 0; ... do some counting ... atomic_fetch_add_explicit( &counter,