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
 

kpua

macrumors 6502
Jul 25, 2006
294
0
Did you try sampling your own coloring scheme to find the bottleneck?
 

kpua

macrumors 6502
Jul 25, 2006
294
0
Run Shark or Instruments or 'sample' on your own code to find what's causing the slow down.
 

varsis

macrumors regular
Original poster
Nov 30, 2005
209
1
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
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
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_.
 

varsis

macrumors regular
Original poster
Nov 30, 2005
209
1
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.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
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.
 

tyr2

macrumors 6502a
May 6, 2006
833
242
Leeds, UK
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.
 

varsis

macrumors regular
Original poster
Nov 30, 2005
209
1
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.
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
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.
 

varsis

macrumors regular
Original poster
Nov 30, 2005
209
1
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.