mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:50:48 +00:00
Little tweak to keep number of concurrent typing dictionaries allocated
reasonably low git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8342 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a1f627a6ad
commit
4a891ca1cf
1 changed files with 22 additions and 6 deletions
|
@ -641,10 +641,13 @@ static NSColor *shadowCol;
|
||||||
{
|
{
|
||||||
if (_formatter != nil)
|
if (_formatter != nil)
|
||||||
{
|
{
|
||||||
|
NSDictionary *attributes;
|
||||||
NSAttributedString *attrStr;
|
NSAttributedString *attrStr;
|
||||||
|
|
||||||
|
attributes = AUTORELEASE ([self _nonAutoreleasedTypingAttributes]);
|
||||||
attrStr = [_formatter attributedStringForObjectValue: _objectValue
|
attrStr = [_formatter attributedStringForObjectValue: _objectValue
|
||||||
withDefaultAttributes: [self _typingAttributes]];
|
withDefaultAttributes: attributes];
|
||||||
|
|
||||||
if (attrStr != nil)
|
if (attrStr != nil)
|
||||||
{
|
{
|
||||||
return attrStr;
|
return attrStr;
|
||||||
|
@ -661,7 +664,7 @@ static NSColor *shadowCol;
|
||||||
NSDictionary *dict;
|
NSDictionary *dict;
|
||||||
NSAttributedString *attrStr;
|
NSAttributedString *attrStr;
|
||||||
|
|
||||||
dict = [self _typingAttributes];
|
dict = AUTORELEASE ([self _nonAutoreleasedTypingAttributes]);
|
||||||
attrStr = [[NSAttributedString alloc] initWithString: _contents
|
attrStr = [[NSAttributedString alloc] initWithString: _contents
|
||||||
attributes: dict];
|
attributes: dict];
|
||||||
return AUTORELEASE (attrStr);
|
return AUTORELEASE (attrStr);
|
||||||
|
@ -1791,13 +1794,21 @@ static NSColor *shadowCol;
|
||||||
return txtCol;
|
return txtCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary*) _typingAttributes
|
/* This method is an exception and returns a non-autoreleased
|
||||||
|
dictionary, so that calling methods can deallocate it immediately
|
||||||
|
using release. Otherwise if many cells are drawn/their size
|
||||||
|
computed, we pile up hundreds or thousands of these objects before they
|
||||||
|
are deallocated at the end of the run loop. */
|
||||||
|
- (NSDictionary*) _nonAutoreleasedTypingAttributes
|
||||||
{
|
{
|
||||||
NSDictionary *attr;
|
NSDictionary *attr;
|
||||||
NSColor *color;
|
NSColor *color;
|
||||||
NSMutableParagraphStyle *paragraphStyle;
|
NSMutableParagraphStyle *paragraphStyle;
|
||||||
|
|
||||||
color = [self textColor];
|
color = [self textColor];
|
||||||
|
/* Note: there are only 6 possible paragraph styles for cells.
|
||||||
|
TODO: Create them once at the beginning, and reuse them for the whole
|
||||||
|
app lifetime. */
|
||||||
paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
||||||
|
|
||||||
if (_cell.wraps)
|
if (_cell.wraps)
|
||||||
|
@ -1817,18 +1828,22 @@ static NSColor *shadowCol;
|
||||||
paragraphStyle, NSParagraphStyleAttributeName,
|
paragraphStyle, NSParagraphStyleAttributeName,
|
||||||
nil];
|
nil];
|
||||||
RELEASE (paragraphStyle);
|
RELEASE (paragraphStyle);
|
||||||
return AUTORELEASE (attr);
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSSize) _sizeText: (NSString*)title
|
- (NSSize) _sizeText: (NSString*)title
|
||||||
{
|
{
|
||||||
NSSize size;
|
NSSize size;
|
||||||
|
NSDictionary *dict;
|
||||||
|
|
||||||
if (title == nil)
|
if (title == nil)
|
||||||
{
|
{
|
||||||
return NSMakeSize (0,0);
|
return NSMakeSize (0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size = [title sizeWithAttributes: [self _typingAttributes]];
|
dict = [self _nonAutoreleasedTypingAttributes];
|
||||||
|
size = [title sizeWithAttributes: dict];
|
||||||
|
RELEASE (dict);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1863,7 +1878,7 @@ static NSColor *shadowCol;
|
||||||
if (title == nil)
|
if (title == nil)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
attributes = [self _typingAttributes];
|
attributes = [self _nonAutoreleasedTypingAttributes];
|
||||||
titleSize = [title sizeWithAttributes: attributes];
|
titleSize = [title sizeWithAttributes: attributes];
|
||||||
|
|
||||||
// Determine y position of text
|
// Determine y position of text
|
||||||
|
@ -1877,6 +1892,7 @@ static NSColor *shadowCol;
|
||||||
cellFrame.size.height = titleSize.height;
|
cellFrame.size.height = titleSize.height;
|
||||||
|
|
||||||
[title drawInRect: cellFrame withAttributes: attributes];
|
[title drawInRect: cellFrame withAttributes: attributes];
|
||||||
|
RELEASE (attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue