theos / logos

Preprocessor that simplifies Objective-C hooking.
https://theos.dev/docs/logos
Other
204 stars 34 forks source link

Refactor %c into generic cached computation functionality #15

Closed rpetrich closed 5 years ago

rpetrich commented 12 years ago

It should be possible to pass arbitrary expressions into a logos macro and have it dedupe and cache them. Existing %c(classname) expressions could be converted to use this functionality internally. Additionally, components within theos itself could use this functionality to trim some of the work they perform (would use this for my internal generator)

Proposed syntax: %cached(x) yields a C rvalue that references the result of the computation x as executed from inside %init; (or the automatically generated initializer if none exists)

Potential extensions: Nested cached expressions could be supported to eliminate duplicate work inside of cached expressions themselves. Further, cached expressions that are used only as a subexpression of other cached expressions could be optimized not to escape the scope of %init Lazy initialization via alternate syntax (with/without thread safety?). Would allow syntax like this to workaround glacial apis: %cached([[[NSCharacterSet characterSetWithCharactersInString:@"_1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"] invertedSet] retain], lazy)

DHowett commented 10 years ago

Wrapped into #60.