ksuther/KSImageNamed-Xcode — pull request #31 by chendo (2013-10-24 03:20:41+00:00)
Title: Eliminate unnecessary CPU usage

`KSImageNamed` normally hooks into `textViewShouldChangeTextInRange:replacementString:`, which causes a lot of `KSImageNamed` methods to be hit *every time* the text view changes.

Here is a paste of Obj-C message sends matching *KSImageNamed* when I press `Return` only once on an empty line: https://gist.github.com/chendo/7130668

After poking around in `DVTTextCompletionController+KSImageNamed` and looking at the trace, it seems that `replacementString` is never nil (at least in Xcode 5.0.1), which is causing `imageCompletions` to be enumerated *every single time* text changes.

This would be particularly bad in a project with many image assets.

This PR removes the textView swizzle and hooks into `DVTTextCompletionListWindow`'s `showInfoPaneForCompletionItem:` and `_hideWindow` methods, so `KSImageNamed` is only run when necessary.

Below is the remaining Obj-C message sends matching *KSImageNamed* when pressing `Return` once on an empty line after applying this PR:

```
-> -[DVTTextCompletionController(KSImageNamed) swizzle_acceptCurrentCompletion]
<- -[DVTTextCompletionController(KSImageNamed) swizzle_acceptCurrentCompletion]
-> -[DVTSourceTextView(KSImageNamedSwizzle) swizzle_shouldAutoCompleteAtLocation:]
-> +[KSImageNamed sharedPlugin]
<- +[KSImageNamed sharedPlugin]
-> -[KSImageNamed completionStringsForType:]
<- -[KSImageNamed completionStringsForType:]
<- -[DVTSourceTextView(KSImageNamedSwizzle) swizzle_shouldAutoCompleteAtLocation:]
-> -[DVTSourceTextView(KSImageNamedSwizzle) swizzle_shouldAutoCompleteAtLocation:]
-> +[KSImageNamed sharedPlugin]
<- +[KSImageNamed sharedPlugin]
-> -[KSImageNamed completionStringsForType:]
<- -[KSImageNamed completionStringsForType:]
<- -[DVTSourceTextView(KSImageNamedSwizzle) swizzle_shouldAutoCompleteAtLocation:]
```

I've only tested this on Xcode 5.0.1.