Improve parsing to avoid redundant copying and stack allocation

I was getting an error with an SVG image that has a large embedded image inside it (using an xlink:href attribute with a `data:image/png;base64` value)—the error was happening in SVGKParser when trying to strncpy the xlink:href attribute. I realized that there should be no need to strncpy the data; instead NSString's initWithBytes:length:encoding can be used directly. I changed the code to do so, which should make it more efficient and also avoids the error I was getting.
Yes. The old version was doing strlen(begin) - strlen(end), and strlen() counts from the pointer until it finds a zero (‘\0’) terminator. This worked because the zero terminator was always further from the begin pointer than from the end pointer, so strlen(begin) was always bigger than strlen(end). However, there’s no need to count string lengths at all—subtracting the begin pointer from the end pointer gives the same length with no counting required.

On Dec 18, 2014, at 12:35 PM, adamgit <notifications@github.com> wrote:

> In Source/Parsers/SVGKParser.m:
> 
> > @@ -873,16 +869,13 @@ static void structuredError		(void * userData,
> >  	for (int i = 0; i < attr_ct * 5; i += 5) {
> >  		const char *begin = (const char *) attrs[i + 3];
> >  		const char *end = (const char *) attrs[i + 4];
> > -		size_t vlen = strlen(begin) - strlen(end);
> If this used to work (begin-end) does your version still work (end-begun)
> 
> —
> Reply to this email directly or view it on GitHub.
>