Skip to content

Instantly share code, notes, and snippets.

@53ningen
Last active April 10, 2016 09:24
Show Gist options
  • Save 53ningen/b86ee464a52689337eb7fa9e51237667 to your computer and use it in GitHub Desktop.
Save 53ningen/b86ee464a52689337eb7fa9e51237667 to your computer and use it in GitHub Desktop.

対象コード

public enum Event<E> {
    case Next(E)
    case Error(ErrorType)
    case Completed
}

public class Subject {
  
    var stoppedEvent: Event<Int>? = nil
  
    func on(event: Event<Int>) {
        guard stoppedEvent != nil else { return }
        switch event {
        case .Next(_): break
        case .Error(_): stoppedEvent = event
        case .Completed: stoppedEvent = event
        }
    }

}

func test() {
    let subject = Subject() 
    subject.on(Event.Next(1))
    subject.on(Event.Completed)
    subject.on(Event.Completed)
}

test()

コンパイル

xcrun swiftc -O opt1.swift -o opt1

結果

int _main(int arg0, int arg1) {
    rbx = arg1;
    *(int32_t *)__TZvOs7Process5_argcVs5Int32 = arg0;
    if (*_globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5 != 0xffffffffffffffff) {
            swift_once(_globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5, _globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5);
    }
    *__TZvOs7Process11_unsafeArgvGSpGSpVs4Int8__ = rbx;
    if (*__TMLC6result7Subject == 0x0) {
            *__TMLC6result7Subject = swift_getInitializedObjCClass(__TMC6result7Subject);
    }
    rax = swift_initStackObject();
    *(rax + 0x10) = 0x0;
    *(int8_t *)(rax + 0x18) = 0x0;
    *(int8_t *)(rax + 0x19) = 0x1;
    return 0x0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment