diff --git a/ChangeLog b/ChangeLog index d52f1eb57..79430da98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2000-12-13 Nicola Pero + + * Headers/gnustep/base/NSRange.h, Source/NSRange.m: Inlined + NSMakeRange. + 2000-12-12 Nicola Pero * Source/NSDebug.m (table_entry): Added peak field. diff --git a/Headers/gnustep/base/NSRange.h b/Headers/gnustep/base/NSRange.h index d058cd591..aed5d4130 100644 --- a/Headers/gnustep/base/NSRange.h +++ b/Headers/gnustep/base/NSRange.h @@ -27,6 +27,9 @@ #include +@class NSException; +@class NXConstantString; + /**** Type, Constant, and Macro Definitions **********************************/ #ifndef MAX @@ -56,7 +59,7 @@ struct _NSRange * All but the most complex functions are declared static inline in this * header file so that they are maximally efficient. In order to provide * true functions (for code modules that don't have this header) this - * header is included in NSGeometry.m where the functions are no longer + * header is included in NSRange.m where the functions are no longer * declared inline. */ #ifdef IN_NSRANGE_M @@ -85,9 +88,31 @@ NSLocationInRange(unsigned location, NSRange range) return (location >= range.location) && (location < NSMaxRange(range)); } -/* Create an NSRange having the specified LOCATION and LENGTH. */ -GS_EXPORT NSRange -NSMakeRange(unsigned int location, unsigned int length); +GS_RANGE_SCOPE NSRange +NSMakeRange(unsigned int location, unsigned int length) GS_RANGE_ATTR; + +GS_RANGE_SCOPE NSRange +NSMakeRange(unsigned int location, unsigned int length) +{ + NSRange range; + unsigned int end = location + length; + + if (end < location || end < length) + { + extern void _NSRangeExceptionRaise (); + /* NB: The implementation of _NSRangeExceptionRaise is: + [NSException raise: NSRangeException + format: @"Range location + length too great"]; */ + + /* _NSRangeExceptionRaise is defined in NSRange.m so that this + file (NSRange.h) can be included without problems in the + implementation of the base classes themselves. */ + _NSRangeExceptionRaise (); + } + range.location = location; + range.length = length; + return range; +} GS_RANGE_SCOPE BOOL NSEqualRanges(NSRange range1, NSRange range2) GS_RANGE_ATTR; diff --git a/Source/NSRange.m b/Source/NSRange.m index cfac3954c..3dd06f83a 100644 --- a/Source/NSRange.m +++ b/Source/NSRange.m @@ -40,22 +40,6 @@ setupCache() } } -NSRange -NSMakeRange(unsigned int location, unsigned int length) -{ - NSRange range; - unsigned int end = location + length; - - if (end < location || end < length) - { - [NSException raise: NSRangeException - format: @"Range location + length too great"]; - } - range.location = location; - range.length = length; - return range; -} - NSRange NSRangeFromString(NSString* string) { @@ -86,3 +70,8 @@ NSStringFromRange(NSRange range) range.location, range.length]; } +void _NSRangeExceptionRaise () +{ + [NSException raise: NSRangeException + format: @"Range location + length too great"]; +}