@@ -491,36 +491,29 @@ void CFAttributedStringSetAttributes(CFMutableAttributedStringRef attrStr, CFRan
491
491
CFIndex numAdditionalItems = CFDictionaryGetCount (replacementAttrs );
492
492
if (numAdditionalItems ) {
493
493
// Extract the new keys and values so we don't do it over and over for each range
494
- createLocalArray (additionalKeys , numAdditionalItems );
495
- createLocalArray (additionalValues , numAdditionalItems );
494
+ createLocalArray (additionalKeys , numAdditionalItems );
495
+ createLocalArray (additionalValues , numAdditionalItems );
496
496
CFDictionaryGetKeysAndValues (replacementAttrs , additionalKeys , additionalValues );
497
-
498
- // CFAttributedStringBeginEditing(attrStr);
497
+
498
+ // CFAttributedStringBeginEditing(attrStr);
499
499
while (range .length ) {
500
500
CFRange effectiveRange ;
501
501
CFMutableDictionaryRef attrs = (CFMutableDictionaryRef )CFRunArrayGetValueAtIndex (attrStr -> attributeArray , range .location , & effectiveRange , NULL );
502
- if (effectiveRange .location == range .location && effectiveRange .length <= range .length && CFGetRetainCount (attrs ) == 1 ) {
503
- // !!! Retain count check cheesy; need to keep our own reference count
504
- // The attributes dictionary can just be modified in place
505
- // Here we are assuming that CFRunArray is not under-reporting the effectiveRange for a given item!
506
- __CFDictionaryAddMultiple (attrs , additionalKeys , additionalValues , numAdditionalItems );
507
- } else {
508
- // Intersect effectiveRange and range
509
- if (effectiveRange .location < range .location ) {
510
- effectiveRange .length -= (range .location - effectiveRange .location );
511
- effectiveRange .location = range .location ;
512
- }
513
- if (effectiveRange .length > range .length ) effectiveRange .length = range .length ;
514
- // We need to make a new copy
515
- attrs = __CFAttributedStringCreateAttributesDictionary (CFGetAllocator (attrStr ), attrs );
516
- __CFDictionaryAddMultiple (attrs , additionalKeys , additionalValues , numAdditionalItems );
517
- CFRunArrayReplace (attrStr -> attributeArray , effectiveRange , attrs , effectiveRange .length );
518
- CFRelease (attrs );
502
+ // Intersect effectiveRange and range
503
+ if (effectiveRange .location < range .location ) {
504
+ effectiveRange .length -= (range .location - effectiveRange .location );
505
+ effectiveRange .location = range .location ;
519
506
}
507
+ if (effectiveRange .length > range .length ) effectiveRange .length = range .length ;
508
+ // We need to make a new copy
509
+ attrs = __CFAttributedStringCreateAttributesDictionary (CFGetAllocator (attrStr ), attrs );
510
+ __CFDictionaryAddMultiple (attrs , additionalKeys , additionalValues , numAdditionalItems );
511
+ CFRunArrayReplace (attrStr -> attributeArray , effectiveRange , attrs , effectiveRange .length );
512
+ CFRelease (attrs );
520
513
range .length -= effectiveRange .length ;
521
514
range .location += effectiveRange .length ;
522
515
}
523
- // CFAttributedStringEndEditing(attrStr);
516
+ // CFAttributedStringEndEditing(attrStr);
524
517
525
518
freeLocalArray (additionalKeys );
526
519
freeLocalArray (additionalValues );
@@ -538,27 +531,20 @@ void CFAttributedStringSetAttribute(CFMutableAttributedStringRef attrStr, CFRang
538
531
CFRange effectiveRange ;
539
532
// effectiveRange.location returned here may be equal to or smaller than range.location
540
533
CFMutableDictionaryRef attrs = (CFMutableDictionaryRef )CFRunArrayGetValueAtIndex (attrStr -> attributeArray , range .location , & effectiveRange , NULL );
541
- if (effectiveRange .location == range .location && effectiveRange .length <= range .length && CFGetRetainCount (attrs ) == 1 ) {
542
- // !!! Retain count check cheesy; need to keep our own reference count)
543
- // The attributes dictionary can just be modified in place
544
- // Here we are assuming that CFRunArray is not under-reporting the effectiveRange for a given item!
534
+ // Intersect effectiveRange and range
535
+ if (effectiveRange .location < range .location ) {
536
+ effectiveRange .length -= (range .location - effectiveRange .location );
537
+ effectiveRange .location = range .location ;
538
+ }
539
+ if (effectiveRange .length > range .length ) effectiveRange .length = range .length ;
540
+ // First check to see if the same value already exists; this will avoid a copy
541
+ CFTypeRef existingValue = CFDictionaryGetValue (attrs , attrName );
542
+ if (!existingValue || !CFEqual (existingValue , value )) {
543
+ // We need to make a new copy
544
+ attrs = __CFAttributedStringCreateAttributesDictionary (CFGetAllocator (attrStr ), attrs );
545
545
CFDictionarySetValue (attrs , attrName , value );
546
- } else {
547
- // Intersect effectiveRange and range
548
- if (effectiveRange .location < range .location ) {
549
- effectiveRange .length -= (range .location - effectiveRange .location );
550
- effectiveRange .location = range .location ;
551
- }
552
- if (effectiveRange .length > range .length ) effectiveRange .length = range .length ;
553
- // First check to see if the same value already exists; this will avoid a copy
554
- CFTypeRef existingValue = CFDictionaryGetValue (attrs , attrName );
555
- if (!existingValue || !CFEqual (existingValue , value )) {
556
- // We need to make a new copy
557
- attrs = __CFAttributedStringCreateAttributesDictionary (CFGetAllocator (attrStr ), attrs );
558
- CFDictionarySetValue (attrs , attrName , value );
559
- CFRunArrayReplace (attrStr -> attributeArray , effectiveRange , attrs , effectiveRange .length );
560
- CFRelease (attrs );
561
- }
546
+ CFRunArrayReplace (attrStr -> attributeArray , effectiveRange , attrs , effectiveRange .length );
547
+ CFRelease (attrs );
562
548
}
563
549
range .length -= effectiveRange .length ;
564
550
range .location += effectiveRange .length ;
@@ -575,26 +561,19 @@ void CFAttributedStringRemoveAttribute(CFMutableAttributedStringRef attrStr, CFR
575
561
while (range .length ) {
576
562
CFRange effectiveRange ;
577
563
CFMutableDictionaryRef attrs = (CFMutableDictionaryRef )CFRunArrayGetValueAtIndex (attrStr -> attributeArray , range .location , & effectiveRange , NULL );
578
- if (effectiveRange .location == range .location && effectiveRange .length <= range .length && CFGetRetainCount (attrs ) == 1 ) {
579
- // !!! Retain count check cheesy; need to keep our own reference count
580
- // The attributes dictionary can just be modified in place
581
- // Here we are assuming that CFRunArray is not under-reporting the effectiveRange for a given item!
564
+ // Intersect effectiveRange and range
565
+ if (effectiveRange .location < range .location ) {
566
+ effectiveRange .length -= (range .location - effectiveRange .location );
567
+ effectiveRange .location = range .location ;
568
+ }
569
+ if (effectiveRange .length > range .length ) effectiveRange .length = range .length ;
570
+ // First check to see if the value is not there; this will avoid a copy
571
+ if (CFDictionaryContainsKey (attrs , attrName )) {
572
+ // We need to make a new copy
573
+ attrs = __CFAttributedStringCreateAttributesDictionary (CFGetAllocator (attrStr ), attrs );
582
574
CFDictionaryRemoveValue (attrs , attrName );
583
- } else {
584
- // Intersect effectiveRange and range
585
- if (effectiveRange .location < range .location ) {
586
- effectiveRange .length -= (range .location - effectiveRange .location );
587
- effectiveRange .location = range .location ;
588
- }
589
- if (effectiveRange .length > range .length ) effectiveRange .length = range .length ;
590
- // First check to see if the value is not there; this will avoid a copy
591
- if (CFDictionaryContainsKey (attrs , attrName )) {
592
- // We need to make a new copy
593
- attrs = __CFAttributedStringCreateAttributesDictionary (CFGetAllocator (attrStr ), attrs );
594
- CFDictionaryRemoveValue (attrs , attrName );
595
- CFRunArrayReplace (attrStr -> attributeArray , effectiveRange , attrs , effectiveRange .length );
596
- CFRelease (attrs );
597
- }
575
+ CFRunArrayReplace (attrStr -> attributeArray , effectiveRange , attrs , effectiveRange .length );
576
+ CFRelease (attrs );
598
577
}
599
578
range .length -= effectiveRange .length ;
600
579
range .location += effectiveRange .length ;
0 commit comments