Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, all closures are represented as a reference word (traced by the GC) and a non-reference word[1], which is a pointer to the actual function entry point (i.e. code). For delegates (i.e. methods bound to an object), the reference is just the object, and the function pointer is the actual code (looked up through the v-table once). So that actually means a call to a first-class function is cheaper than a virtual call--it is literally an indirect call to the code pointer, passing the receiver object as the first argument.

[1] The two words even become separate, independent scalar values in the compiler IR. Thus the runtime support is minimal, in that it doesn't know anything about multiple-word values: the GC just needs to know whether a word is a reference or not.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: