Why can't we use C-strings as SELs?

后端 未结 1 543
我在风中等你
我在风中等你 2021-02-05 17:05

So, I\'ve been messing around with the objc-runtime again (surprise surprise), and I found an interesting block of code here:

const char *sel_getName(SEL sel) {
         


        
相关标签:
1条回答
  • 2021-02-05 17:31

    Selectors are interned C strings and are compared by their address, not their contents. The string contents is only used for converting to/from an external string representation. Interning is done to improve performance--when the runtime is looking up the method implementation that matches a selector it can compare the selector pointers directly instead of dereferencing each pointer and comparing the characters.

    0 讨论(0)
提交回复
热议问题