diff --git a/AppKit/CPColorPanel.j b/AppKit/CPColorPanel.j index d00baa311..c30c07cab 100644 --- a/AppKit/CPColorPanel.j +++ b/AppKit/CPColorPanel.j @@ -483,13 +483,12 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie"; ]; } - var cookieValue = eval(cookieValue), - result = []; + var cookieValue = eval(cookieValue); - for (var i = 0; i < cookieValue.length; i++) - result.push([CPColor colorWithHexString:cookieValue[i]]); - - return result; + return [cookieValue arrayByApplyingBlock:function(value, _) + { + return [CPColor colorWithHexString:value]; + }]; } - (CPArray)saveColorList diff --git a/AppKit/CPGradient.j b/AppKit/CPGradient.j index dfa7a3437..126e43995 100644 --- a/AppKit/CPGradient.j +++ b/AppKit/CPGradient.j @@ -70,11 +70,12 @@ CPGradientDrawsAfterEndingLocation = kCGGradientDrawsAfterEndLocation; { if (self = [super init]) { - var cgColors = [], - count = [someColors count], - colorSpace = [aColorSpace CGColorSpace] || CGColorSpaceCreateDeviceRGB; - for (var i = 0; i < count; i++) - cgColors.push(CGColorCreate(colorSpace, [someColors[i] components])); + var colorSpace = [aColorSpace CGColorSpace] || CGColorSpaceCreateDeviceRGB, + cgColors = [someColors arrayByApplyingBlock:function(color, _) + { + return CGColorCreate(colorSpace, [color components]) + }]; + _gradient = CGGradientCreateWithColors(colorSpace, cgColors, someLocations); } diff --git a/AppKit/CPGraphics.j b/AppKit/CPGraphics.j index 380bea393..207e05c8c 100644 --- a/AppKit/CPGraphics.j +++ b/AppKit/CPGraphics.j @@ -43,10 +43,10 @@ function CPDrawTiledRects( if (sides.length != grays.length) [CPException raise:CPInvalidArgumentException reason:@"sides (length: " + sides.length + ") and grays (length: " + grays.length + ") must have the same length."]; - var colors = []; - - for (var i = 0; i < grays.length; ++i) - colors.push([CPColor colorWithCalibratedWhite:grays[i] alpha:1.0]); + var colors = [grays arrayByApplyingBlock:function(gray, _) + { + return [CPColor colorWithCalibratedWhite:gray alpha:1.0]; + }]; return CPDrawColorTiledRects(boundsRect, clipRect, sides, colors); } diff --git a/AppKit/CPPopUpButton.j b/AppKit/CPPopUpButton.j index 09aecb6fe..77c6cda06 100644 --- a/AppKit/CPPopUpButton.j +++ b/AppKit/CPPopUpButton.j @@ -361,15 +361,10 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down"); */ - (CPArray)itemTitles { - var titles = [], - items = [self itemArray], - index = 0, - count = [items count]; - - for (; index < count; ++index) - titles.push([items[index] title]); - - return titles; + return [[self itemArray] arrayByApplyingBlock:function(item, _) + { + return [item title]; + }]; } /*! diff --git a/AppKit/CPThemeBlend.j b/AppKit/CPThemeBlend.j index 8455bd4c0..a34544841 100644 --- a/AppKit/CPThemeBlend.j +++ b/AppKit/CPThemeBlend.j @@ -64,12 +64,10 @@ */ - (CPArray)themeNames { - var names = []; - - for (var i = 0; i < _themes.length; ++i) - names.push(_themes[i].substring(0, _themes[i].indexOf(".keyedtheme"))); - - return names; + return [_themes arrayByApplyingBlock:function(theme, _) + { + return theme.substring(0, theme.indexOf(".keyedtheme")); + }]; } - (void)loadWithDelegate:(id)aDelegate diff --git a/AppKit/CPToolbar.j b/AppKit/CPToolbar.j index 49c78924e..8954c7160 100644 --- a/AppKit/CPToolbar.j +++ b/AppKit/CPToolbar.j @@ -459,11 +459,10 @@ var CPToolbarsByIdentifier = nil, /* @ignore */ - (id)_itemsWithIdentifiers:(CPArray)identifiers { - var items = []; - for (var i = 0; i < identifiers.length; i++) - [items addObject:[self _itemForItemIdentifier:identifiers[i] willBeInsertedIntoToolbar:NO]]; - - return items; + return [identifiers arrayByApplyingBlock:function(identifier, _) + { + return [self _itemForItemIdentifier:identifier willBeInsertedIntoToolbar:NO]; + }]; } /* @ignore */ diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index bb183bd99..6d24c1985 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -1857,11 +1857,10 @@ function CPWindowObjectList() function CPWindowList() { - var windowObjectList = CPWindowObjectList(), - windowList = []; + var windowObjectList = CPWindowObjectList(); - for (var i = 0, count = [windowObjectList count]; i < count; i++) - windowList.push([windowObjectList[i] windowNumber]); - - return windowList; + return [windowObjectList arrayByApplyingBlock:function(windowObject, _) + { + return [windowObject windowNumber]; + }]; } diff --git a/Foundation/CPAttributedString.j b/Foundation/CPAttributedString.j index 04c131631..7badf601e 100755 --- a/Foundation/CPAttributedString.j +++ b/Foundation/CPAttributedString.j @@ -763,13 +763,10 @@ - (void)setAttributedString:(CPAttributedString)aString { _string = aString._string; - _rangeEntries = []; - - var i = 0, - count = aString._rangeEntries.length; - - for (; i < count; i++) - _rangeEntries.push(copyRangeEntry(aString._rangeEntries[i])); + _rangeEntries = [aString._rangeEntries arrayByApplyingBlock:function(entry, _) + { + return copyRangeEntry(entry); + }]; } //Private methods diff --git a/Foundation/CPBundle.j b/Foundation/CPBundle.j index 069e0e6eb..8c3ab2918 100644 --- a/Foundation/CPBundle.j +++ b/Foundation/CPBundle.j @@ -212,15 +212,12 @@ var CPBundlesForURLStrings = { }; - (CPArray)staticResourceURLs { - var staticResourceURLs = [], - staticResources = _bundle.staticResources(), - index = 0, - count = [staticResources count]; + var staticResources = _bundle.staticResources(); - for (; index < count; ++index) - [staticResourceURLs addObject:staticResources[index].URL()]; - - return staticResourceURLs; + return [staticResources arrayByApplyingBlock:function(resource, _) + { + return resource.URL(); + }]; } - (CPArray)environments diff --git a/Foundation/CPIndexSet.j b/Foundation/CPIndexSet.j index c9f94fddb..e23f4a451 100644 --- a/Foundation/CPIndexSet.j +++ b/Foundation/CPIndexSet.j @@ -1018,14 +1018,13 @@ var CPIndexSetCountKey = @"CPIndexSetCountKey", if (self) { _count = [aCoder decodeIntForKey:CPIndexSetCountKey]; - _ranges = []; - var rangeStrings = [aCoder decodeObjectForKey:CPIndexSetRangeStringsKey], - index = 0, - count = rangeStrings.length; + var rangeStrings = [aCoder decodeObjectForKey:CPIndexSetRangeStringsKey]; - for (; index < count; ++index) - _ranges.push(CPRangeFromString(rangeStrings[index])); + _ranges = [rangeStrings arrayByApplyingBlock:function(range, _) + { + return CPRangeFromString(range); + }]; } return self; diff --git a/Foundation/CPKeyedArchiver.j b/Foundation/CPKeyedArchiver.j index e4e0d7bbd..7c074c383 100644 --- a/Foundation/CPKeyedArchiver.j +++ b/Foundation/CPKeyedArchiver.j @@ -380,12 +380,10 @@ var _CPKeyedArchiverStringClass = Nil, /* @ignore */ - (void)_encodeArrayOfObjects:(CPArray)objects forKey:(CPString)aKey { - var i = 0, - count = objects.length, - references = []; - - for (; i < count; ++i) - [references addObject:_CPKeyedArchiverEncodeObject(self, objects[i], NO)]; + var references = [objects arrayByApplyingBlock:function(object, _) + { + return _CPKeyedArchiverEncodeObject(self, object, NO); + }]; [_plistObject setObject:references forKey:aKey]; } diff --git a/Foundation/CPPredicate/_CPAggregateExpression.j b/Foundation/CPPredicate/_CPAggregateExpression.j index 688166398..d3bdfc406 100644 --- a/Foundation/CPPredicate/_CPAggregateExpression.j +++ b/Foundation/CPPredicate/_CPAggregateExpression.j @@ -34,6 +34,7 @@ if (self) _aggregate = collection; + return self; } @@ -55,41 +56,28 @@ - (id)expressionValueWithObject:(id)object context:(CPDictionary)context { - var eval_array = [CPArray array], - collection = [_aggregate objectEnumerator], - exp; - - while ((exp = [collection nextObject]) !== nil) + return [_aggregate arrayByApplyingBlock:function(exp, _) { - var eval = [exp expressionValueWithObject:object context:context]; - [eval_array addObject:eval]; - } - - return eval_array; + return [exp expressionValueWithObject:object context:context]; + }]; } - (CPString)description -{ - var i = 0, - count = [_aggregate count], - result = "{"; +{ + var descriptions = [_aggregate arrayByApplyingBlock:function(exp, _) + { + return [exp description]; + }]; - for (; i < count; i++) - result = result + [CPString stringWithFormat:@"%s%s", [[_aggregate objectAtIndex:i] description], (i + 1 < count) ? @", " : @""]; - - result = result + "}"; - - return result; + return "{" + [descriptions componentsJoinedByString:","] + "}" ; } - (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables { - var subst_array = [CPArray array], - count = [_aggregate count], - i = 0; - - for (; i < count; i++) - [subst_array addObject:[[_aggregate objectAtIndex:i] _expressionWithSubstitutionVariables:variables]]; + var subst_array = [_aggregate arrayByApplyingBlock:function(exp, _) + { + return [exp _expressionWithSubstitutionVariables:variables]; + }]; return [CPExpression expressionForAggregate:subst_array]; } diff --git a/Foundation/CPPredicate/_CPFunctionExpression.j b/Foundation/CPPredicate/_CPFunctionExpression.j index 394c93612..b0d854dd9 100644 --- a/Foundation/CPPredicate/_CPFunctionExpression.j +++ b/Foundation/CPPredicate/_CPFunctionExpression.j @@ -143,11 +143,10 @@ - (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables { var operand = [[self operand] _expressionWithSubstitutionVariables:variables], - args = [CPArray array], - i = 0; - - for (; i < _argc; i++) - [args addObject:[_arguments[i] _expressionWithSubstitutionVariables:variables]]; + args = [_arguments arrayByApplyingBlock:function(arg, _) + { + return [arg _expressionWithSubstitutionVariables:variables]; + }]; return [CPExpression expressionForFunction:operand selectorName:[self _function] arguments:args]; }