Upgrade to Pro — share decks privately, control downloads, hide ads and more …

@_specialized なお話し

matuyuji
December 26, 2016

@_specialized なお話し

Swift の @_specialized について

matuyuji

December 26, 2016
Tweet

More Decks by matuyuji

Other Decks in Programming

Transcript

  1. !@TQFDJBMJ[F public class Game<T : Pingable> : Playable { var

    t : T public init (_ v : T) {t = v} @_specialize(Int) public func play() { for _ in 0...100_000_000 { t = t.ping() } } }
  2. public protocol Pingable { func ping() -> Self } public

    protocol Playable { func play() } extension Int : Pingable { public func ping() -> Int { return self + 1 } } public class Game<T : Pingable> : Playable { var t : T public init (_ v : T) {t = v} @_specialize(Int) public func play() { for _ in 0...100_000_000 { t = t.ping() } } } Game(10).play() Application.swift Framework.swift
  3. $ diff -u =(nm -naj Framework.build/Framework.swift.o) \ =(nm -naj FrameworkSp.build/Framework.swift.o)

    $ diff -u =(nm -na Framework.build/Framework.swift.o | head -n 25) \ =(nm -na FrameworkSp.build/Framework.swift.o | head -n 25 ) \ | swift demangle --- /tmp/zshPdqiBd 2016-12-26 16:11:46.000000000 +0900 +++ /tmp/zshdhTiwz 2016-12-26 16:11:46.000000000 +0900 @@ -21,5 +21,5 @@ 00000000000000e0 T _type metadata accessor for Framework.Game 0000000000000110 T _rt_swift_allocObject 0000000000000120 T _Framework.Game.play () -> () -0000000000000220 T _Framework.Game.__deallocating_deinit -0000000000000260 T _Framework.Game.deinit +0000000000000270 T _Framework.Game.__deallocating_deinit +00000000000002b0 T _Framework.Game.deinit