Skip to content

Commit

Permalink
remove direct function calls to Obj-C methods
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R-packages/trunk/Mac-GUI@7916 694ef91d-65df-0310-b7bb-92e67a308ead
  • Loading branch information
s-u committed Jan 25, 2021
1 parent 11ec15e commit 19d6a0c
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 101 deletions.
10 changes: 0 additions & 10 deletions NoodleLineNumberView.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ static inline id NSArrayObjectAtIndex(NSArray *self, NSUInteger i)
// Add support for selection by clicking/dragging
NSUInteger dragSelectionStartLine;

SEL lineNumberForCharacterIndexSel;
IMP lineNumberForCharacterIndexIMP;
SEL lineRangeForRangeSel;
SEL numberWithUnsignedIntegerSel;
IMP numberWithUnsignedIntegerIMP;
SEL addObjectSel;
IMP addObjectIMP;
SEL rangeOfLineSel;
Class numberClass;

NSLayoutManager *layoutManager;
NSTextContainer *container;
NSTextView *clientView;
Expand Down
26 changes: 6 additions & 20 deletions NoodleLineNumberView.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,8 @@ - (id)initWithScrollView:(NSScrollView *)aScrollView
[self updateGutterThicknessConstants];
currentRuleThickness = 0.0f;

// Cache loop methods for speed
lineNumberForCharacterIndexSel = @selector(lineNumberForCharacterIndex:);
lineNumberForCharacterIndexIMP = [self methodForSelector:lineNumberForCharacterIndexSel];
lineRangeForRangeSel = @selector(lineRangeForRange:);
addObjectSel = @selector(addObject:);
numberWithUnsignedIntegerSel = @selector(numberWithUnsignedInteger:);
numberWithUnsignedIntegerIMP = [NSNumber methodForSelector:numberWithUnsignedIntegerSel];
rangeOfLineSel = @selector(getLineStart:end:contentsEnd:forRange:);

currentNumberOfLines = 1;
lineWrapping = NO;
numberClass = [NSNumber class];

normalBackgroundColor = [[NSColor colorWithCalibratedWhite: 0.95 alpha: 1.0] retain];
foldedBackgroundColor = [[NSColor colorWithCalibratedWhite: 0.85 alpha: 1.0] retain];
Expand Down Expand Up @@ -292,7 +282,7 @@ - (NSUInteger)lineNumberForLocation:(CGFloat)location
// It doesn't show up in the glyphs so would not be accounted for.
range.length++;

for (line = (NSUInteger)(*lineNumberForCharacterIndexIMP)(self, lineNumberForCharacterIndexSel, range.location); line < count; line++)
for (line = [self lineNumberForCharacterIndex: range.location]; line < count; line++)
{

rects = [layoutManager rectArrayForCharacterRange:NSMakeRange([NSArrayObjectAtIndex(lines, line) unsignedIntegerValue], 0)
Expand Down Expand Up @@ -396,7 +386,7 @@ - (void)drawHashMarksAndLabelsInRect:(NSRect)aRect
BOOL flipped = [self isFlipped];


for (line = (NSUInteger)(*lineNumberForCharacterIndexIMP)(self, lineNumberForCharacterIndexSel, range.location); line < count; line++)
for (line = [self lineNumberForCharacterIndex: range.location]; line < count; line++)
{
index = [NSArrayObjectAtIndex(lines, line) unsignedIntegerValue];

Expand Down Expand Up @@ -787,21 +777,17 @@ - (void)calculateLines

index = 0;

// Cache loop methods for speed
IMP rangeOfLineIMP = [textString methodForSelector:rangeOfLineSel];
addObjectIMP = [lineIndices methodForSelector:addObjectSel];

do
{
(void)(*addObjectIMP)(lineIndices, addObjectSel, (*numberWithUnsignedIntegerIMP)(numberClass, numberWithUnsignedIntegerSel, index));
(*rangeOfLineIMP)(textString, rangeOfLineSel, NULL, &index, NULL, NSMakeRange(index, 0));
[lineIndices addObject: [NSNumber numberWithUnsignedInteger: index]];
[textString getLineStart:NULL end:&index contentsEnd:NULL forRange:NSMakeRange(index, 0)];
}
while (index < stringLength);

// Check if text ends with a new line.
(*rangeOfLineIMP)(textString, rangeOfLineSel, NULL, &lineEnd, &contentEnd, NSMakeRange([[lineIndices lastObject] intValue], 0));
[textString getLineStart:NULL end:&lineEnd contentsEnd:&contentEnd forRange:NSMakeRange([[lineIndices lastObject] intValue], 0)];
if (contentEnd < lineEnd)
(void)(*addObjectIMP)(lineIndices, addObjectSel, (*numberWithUnsignedIntegerIMP)(numberClass, numberWithUnsignedIntegerSel, index));
[lineIndices addObject: [NSNumber numberWithUnsignedInteger: index]];

NSUInteger lineCount = [lineIndices count];
if(lineCount < 100)
Expand Down
4 changes: 0 additions & 4 deletions RController.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@
WebView *currentWebViewForFindAction;
id searchInWebViewWindow;

IMP _nextEventImp;
IMP _sendEventImp;
IMP _doProcessImp;

NSTimer *timer;
NSTimer *RLtimer;
NSTimer *Flushtimer;
Expand Down
31 changes: 9 additions & 22 deletions RController.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@

static RController* sharedRController;

static SEL _nextEventSel;
static SEL _sendEventSel;
static SEL _doProcessSel;

static inline const char* NSStringUTF8String(NSString* self)
{
typedef const char* (*SPUTF8StringMethodPtr)(NSString*, SEL);
Expand Down Expand Up @@ -216,14 +212,6 @@ - (id) init {

filteredHistory = nil;

_nextEventSel = @selector(nextEventMatchingMask:untilDate:inMode:dequeue:);
_sendEventSel = @selector(sendEvent:);
_doProcessSel = @selector(doProcessEvents:);

_nextEventImp = [NSApp methodForSelector:_nextEventSel];
_sendEventImp = [NSApp methodForSelector:_sendEventSel];
_doProcessImp = [self methodForSelector:_doProcessSel];

specialCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"\r\b\a"] retain];

[[NSNotificationCenter defaultCenter] addObserver:self
Expand Down Expand Up @@ -1395,7 +1383,7 @@ - (char*) handleReadConsole: (int) addtohist

while ([consoleInputQueue count]==0) {
processingEvents = NO; // we should be at the top level, so for sanity reasons make sure we always process events
(_doProcessImp)(self, _doProcessSel, YES);
[self doProcessEvents: YES];
}

currentConsoleInput = [consoleInputQueue objectAtIndex:0];
Expand Down Expand Up @@ -1696,9 +1684,8 @@ - (int) handleSystemCommand: (const char*) cmd
// to be processed in all cases, even if system was called from within
// the event handler and as such can run recursively
NSEvent *event;
if((event = (_nextEventImp)(NSApp, _nextEventSel, NSAnyEventMask, [NSDate dateWithTimeIntervalSinceNow:0.05], NSDefaultRunLoopMode, YES)))
(_sendEventImp)(NSApp, _sendEventSel, event);

if((event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.05] inMode:NSDefaultRunLoopMode dequeue:YES]))
[NSApp sendEvent: event];
}
if(breakPending) {
kill(pid, SIGINT);
Expand Down Expand Up @@ -3080,11 +3067,11 @@ - (void) doProcessEvents: (BOOL) blocking
#ifdef USE_POOLS
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#endif
if (blocking){
(_sendEventImp)(NSApp, _sendEventSel, (_nextEventImp)(NSApp, _nextEventSel, NSAnyEventMask, [NSDate distantFuture], NSDefaultRunLoopMode, YES));
} else {
while((event = (_nextEventImp)(NSApp, _nextEventSel, NSAnyEventMask, [NSDate dateWithTimeIntervalSinceNow:0.0001], NSDefaultRunLoopMode, YES)))
(_sendEventImp)(NSApp, _sendEventSel, event);
if (blocking)
[NSApp sendEvent: [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES]];
else {
while((event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.0001] inMode:NSDefaultRunLoopMode dequeue:YES]))
[NSApp sendEvent: event];
}
#ifdef USE_POOLS
[pool release];
Expand Down Expand Up @@ -3112,7 +3099,7 @@ - (void) doProcessEvents: (BOOL) blocking

- (void) handleProcessEvents
{
(_doProcessImp)(self, _doProcessSel, NO);
[self doProcessEvents: NO];
}


Expand Down
3 changes: 0 additions & 3 deletions RScriptEditorGlyphGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
id <NSGlyphStorage> _destination;
RScriptEditorTextStorage *theTextStorage;
NSGlyph nullGlyph;
IMP _attrStrImp;
IMP _foldImp;
IMP _foldindImp;
NSInteger sizeOfNSGlyph;

}
Expand Down
16 changes: 0 additions & 16 deletions RScriptEditorGlyphGenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,13 @@
#import "RScriptEditorLayoutManager.h"
#import "PreferenceKeys.h"

static SEL _attrStrSel;
static SEL _foldSel;
static SEL _foldindSel;

@implementation RScriptEditorGlyphGenerator

+ (void)initialize
{
if ([self class] == [RScriptEditorGlyphGenerator class]) {
_attrStrSel = @selector(attributedString);
_foldSel = @selector(foldedRangeAtIndex:);
_foldindSel = @selector(foldedForIndicatorAtIndex:);
}
}

- (id)init
{
self = [super init];

if (self != nil) {
_attrStrImp = [self methodForSelector:_attrStrSel];
nullGlyph = NSNullGlyph;
sizeOfNSGlyph = sizeof(NSGlyph);
}
Expand All @@ -75,8 +61,6 @@ - (void)setTextStorage:(RScriptEditorTextStorage*)textStorage
{
if(theTextStorage) [theTextStorage release];
theTextStorage = [textStorage retain];
_foldImp = [theTextStorage methodForSelector:_foldSel];
_foldindImp = [theTextStorage methodForSelector:_foldindSel];
}

- (void)generateGlyphsForGlyphStorage:(id <NSGlyphStorage>)glyphStorage desiredNumberOfCharacters:(NSUInteger)nChars glyphIndex:(NSUInteger *)glyphIndex characterIndex:(NSUInteger *)charIndex
Expand Down
7 changes: 0 additions & 7 deletions RScriptEditorTextStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@

id selfDelegate;

IMP _getImp;
IMP _setImp;
IMP _strImp;
IMP _replImp;
IMP _editImp;
IMP _getlImp;

}

- (id)initWithDelegate:(id)theDelegate;
Expand Down
18 changes: 6 additions & 12 deletions RScriptEditorTextStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ - (id)initWithDelegate:(id)theDelegate

if (self != nil) {
_attributedString = [[NSTextStorage alloc] init];
_getImp = [_attributedString methodForSelector:_getSel];
_setImp = [_attributedString methodForSelector:_setSel];
_strImp = [_attributedString methodForSelector:_strSel];
_replImp = [_attributedString methodForSelector:_replSel];
_editImp = [self methodForSelector:_editSel];
_getlImp = [_attributedString methodForSelector:_getlSel];

selfDelegate = (RScriptEditorTextView*)theDelegate;
[self setDelegate:theDelegate];
Expand Down Expand Up @@ -304,13 +298,13 @@ - (NSRange)foldedRangeAtIndex:(NSInteger)index

- (NSString *)string
{
return (*_strImp)(_attributedString, _strSel);
return _attributedString ? [_attributedString string] : nil;
}

- (NSDictionary *)attributesAtIndex:(NSUInteger)location effectiveRange:(NSRangePointer)range
{

NSDictionary *attributes = (*_getImp)(_attributedString, _getSel, location, range);
NSDictionary *attributes = [_attributedString attributesAtIndex:location effectiveRange:range];

if(!foldedCounter || location > [_attributedString length]) return attributes;

Expand Down Expand Up @@ -381,14 +375,14 @@ - (void)edited:(NSUInteger)mask range:(NSRange)oldRange changeInLength:(NSIntege
// NSMutableAttributedString primitives
- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str
{
(*_replImp)(_attributedString, _replSel, range, str);
(*_editImp)(self, _editSel, NSTextStorageEditedCharacters, range, [str length] - range.length);
[_attributedString replaceCharactersInRange:range withString:str];
[self edited:NSTextStorageEditedCharacters range:range changeInLength: [str length] - range.length];
}

- (void)setAttributes:(NSDictionary *)attrs range:(NSRange)range
{
(*_setImp)(_attributedString, _setSel, attrs, range);
(*_editImp)(self, _editSel, NSTextStorageEditedAttributes, range, 0);
[_attributedString setAttributes:attrs range:range];
[self edited:NSTextStorageEditedAttributes range:range changeInLength:0];
}

// Attribute Fixing Overrides
Expand Down
1 change: 0 additions & 1 deletion RScriptEditorTypeSetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
{

RScriptEditorTextStorage *_attributedString;
IMP _foldImp;

}

Expand Down
8 changes: 2 additions & 6 deletions RScriptEditorTypeSetter.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,11 @@

@implementation RScriptEditorTypeSetter

static SEL _foldSel;

- (id)init
{
self = [super init];
if (nil == self) return nil;
_attributedString = nil;
_foldSel = @selector(foldedForIndicatorAtIndex:);
return self;
}

Expand All @@ -59,13 +56,12 @@ - (void)setTextStorage:(RScriptEditorTextStorage*)textStorage
{
if(_attributedString) [_attributedString release];
_attributedString = [textStorage retain];
_foldImp = [_attributedString methodForSelector:_foldSel];

}

- (NSTypesetterControlCharacterAction)actionForControlCharacterAtIndex:(NSUInteger)charIndex
{
if (_foldImp && (NSInteger)(*_foldImp)(_attributedString, _foldSel, charIndex) > -1) return NSTypesetterZeroAdvancementAction;
if (_attributedString && [_attributedString foldedForIndicatorAtIndex:charIndex] > -1)
return NSTypesetterZeroAdvancementAction;
return [super actionForControlCharacterAtIndex:charIndex];
}

Expand Down

0 comments on commit 19d6a0c

Please sign in to comment.