Differences From Artifact [bc650a7105]:
- File
src/OFXMLParser.m
— part of check-in
[d4b379485a]
at
2010-07-08 08:57:00
on branch trunk
— Don't retain + autorelease objects returned from collections.
This increases performance and should not need to be handled by the
programmer in most cases. (user: js, size: 15829) [annotate] [blame] [check-ins using]
To Artifact [86d4782143]:
- File src/OFXMLParser.m — part of check-in [4c57833cfa] at 2010-07-08 18:49:36 on branch trunk — Resolve attribute namespaces after all attributes have been parsed. (user: js, size: 16543) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
48 49 50 51 52 53 54 55 56 57 58 59 60 61 | if ((tmp = [carray[i] objectForKey: prefix]) != nil) return tmp; } return nil; } @implementation OFXMLParser + parser { return [[[self alloc] init] autorelease]; } | > > > > > > > > > > > > > > > > > > > > > > > > > | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | if ((tmp = [carray[i] objectForKey: prefix]) != nil) return tmp; } return nil; } static OF_INLINE void resolve_attr_namespace(OFXMLAttribute *attr, OFString *prefix, OFString *ns, OFArray *namespaces, Class isa) { OFString *attr_ns; OFString *attr_prefix = attr->namespace; if ([[attr name] isEqual: @"xmlns"] && attr_prefix == nil) { [attr->namespace release]; attr->namespace = nil; return; } attr_ns = namespace_for_prefix( (attr_prefix != nil ? attr_prefix : prefix), namespaces); if ((attr_prefix != nil && attr_ns == nil) || (ns != nil && attr_ns == nil)) @throw [OFUnboundNamespaceException newWithClass: isa prefix: attr_prefix]; [attr->namespace release]; attr->namespace = [attr_ns retain]; } @implementation OFXMLParser + parser { return [[[self alloc] init] autorelease]; } |
︙ | ︙ | |||
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | } break; /* Inside a tag, name found */ case OF_XMLPARSER_IN_TAG: if (buf[i] == '>' || buf[i] == '/') { OFString *ns; ns = namespace_for_prefix(prefix, namespaces); if (prefix != nil && ns == nil) @throw [OFUnboundNamespaceException newWithClass: isa prefix: prefix]; pool = [[OFAutoreleasePool alloc] init]; [delegate parser: self didStartElement: name withPrefix: prefix namespace: ns attributes: attrs]; | > > > > > > | 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | } break; /* Inside a tag, name found */ case OF_XMLPARSER_IN_TAG: if (buf[i] == '>' || buf[i] == '/') { OFString *ns; OFXMLAttribute **attrs_c = [attrs cArray]; size_t j, attrs_cnt = [attrs count]; ns = namespace_for_prefix(prefix, namespaces); if (prefix != nil && ns == nil) @throw [OFUnboundNamespaceException newWithClass: isa prefix: prefix]; for (j = 0; j < attrs_cnt; j++) resolve_attr_namespace(attrs_c[j], prefix, ns, namespaces, isa); pool = [[OFAutoreleasePool alloc] init]; [delegate parser: self didStartElement: name withPrefix: prefix namespace: ns attributes: attrs]; |
︙ | ︙ | |||
426 427 428 429 430 431 432 | last = i + 1; state = OF_XMLPARSER_IN_ATTR_VALUE; break; /* Looking for attribute value */ case OF_XMLPARSER_IN_ATTR_VALUE: if (buf[i] == delim) { | < < < < | < < | | 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | last = i + 1; state = OF_XMLPARSER_IN_ATTR_VALUE; break; /* Looking for attribute value */ case OF_XMLPARSER_IN_ATTR_VALUE: if (buf[i] == delim) { OFString *attr_val; len = i - last; if (len > 0) [cache appendCStringWithoutUTF8Checking: buf + last length: len]; pool = [[OFAutoreleasePool alloc] init]; attr_val = transform_string(cache, self); if (attrPrefix == nil && [attrName isEqual: @"xmlns"]) [[namespaces lastObject] setObject: attr_val forKey: @""]; if ([attrPrefix isEqual: @"xmlns"]) [[namespaces lastObject] setObject: attr_val forKey: attrName]; if (attrs == nil) attrs = [[OFMutableArray alloc] init]; [attrs addObject: [OFXMLAttribute attributeWithName: attrName namespace: attrPrefix stringValue: attr_val]]; [pool release]; [cache setToCString: ""]; [attrName release]; [attrPrefix release]; |
︙ | ︙ |