Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

varsis

macrumors regular
Original poster
Nov 30, 2005
209
1
Hi,

I currently use the textContainer delegate to color my NSTextView. But The problem being it is VERY slow. I use regex to find the right tags but when loading large files it takes forever. I am using css coloring. I tried it in CSS edit and it loaded extremely fast.

What I am looking for is a very fast way to load the right syntax...

Thanks
Chris
 
Did you try sampling your own coloring scheme to find the bottleneck?
 
Run Shark or Instruments or 'sample' on your own code to find what's causing the slow down.
 
Run Shark or Instruments or 'sample' on your own code to find what's causing the slow down.

Il try that but I don't think it's the code but it's the method, like it's not that SLOW but it's slow enough and when compared to css edit coloring it it's incredibly slow.. 2-3 second to syntax a 60,000 characters... Using regex methods...

Chris
 
Il try that but I don't think it's the code but it's the method, like it's not that SLOW but it's slow enough and when compared to css edit coloring it it's incredibly slow.. 2-3 second to syntax a 60,000 characters... Using regex methods...

Chris

That's why you use Shark, so that you don't "think" what is slow but you _know_.
 
That's why you use Shark, so that you don't "think" what is slow but you _know_.

Never Used shark and don't know how but Il give it a try but here is the code VERY simple.

Code:
	NSString *regexStringProps   = @"[A-Za-z0-9-#.>:., _*]+\\:"; 
	RKEnumerator *matchEnumerator = [string matchEnumeratorWithRegex:regexStringProps];
	while([matchEnumerator nextRanges] != NULL) {
		//NSLog(@"%@ Each Peice",NSStringFromRange([matchEnumerator currentRange]));
		NSRange propsRange = [matchEnumerator currentRange];
		propsRange.length = propsRange.length-1;
		[textStorage addAttribute:NSForegroundColorAttributeName
							value:orange
							range:propsRange];	
	}

The above matches code before the ":" in css lines.
 
There is absolutely no point in looking at the code if you haven't done any measuring. It's a waste of time. To use Shark: Start Shark. Select the application to profile. Click on "Start". It couldn't be any easier.
 
Ok I don't know how RKEnumerator works or entirely what you're tying to do here but couldn't you replace [A-Za-z0-9-#.>:., _*]+ with \S+ (i.e. match non white space). Which would be quicker to process that a bunch of ranges.

Just a thought.
 
Ok I don't know how RKEnumerator works or entirely what you're tying to do here but couldn't you replace [A-Za-z0-9-#.>:., _*]+ with \S+ (i.e. match non white space). Which would be quicker to process that a bunch of ranges.

Just a thought.

Used shark didn't see anything incriminating... The function seemed to run fine according to shark.
 
Shark doesn't tell you whether it ran fine or not. It tells you how much time was spent on each line, each function, each asm instruction, etc... with tools for digging into that information and organizing it.
 
Shark doesn't tell you whether it ran fine or not. It tells you how much time was spent on each line, each function, each asm instruction, etc... with tools for digging into that information and organizing it.

Found the Solutions, Turns out Regex Kit uses PCRE to find issues with the Regex commands. But PCRE only supports only UTF-8 But the work around it to use ASCII encoding, which allows your code to run more or less in either UTF-8 or UTF-16 without conversion. Would convert UTF-8 to UTF-16 to UTF-8.

Using ACSII it doesn't need to do this.

Code:
NSString *string = [NSString stringWithCString:[**PLACE YOUR NSSTRING HERE** cStringUsingEncoding:NSASCIIStringEncoding] encoding:NSASCIIStringEncoding];

Does the Trick now loads each regex in about 3 thousandths of a second. Versus the 2 seconds.

Here is a article on this: http://lists.apple.com/archives/xcode-users/2008/Mar/msg00329.html
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.