From 0dfcfd4814468e949fc34b87f8021271e99f04f0 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Tue, 23 May 2006 19:29:52 +0000 Subject: [PATCH] Minor substring optimisation git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22975 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 2 ++ Source/GSString.m | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ChangeLog b/ChangeLog index 169ce133a..f2348630b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ it needed more data even though it had actually completed. * Source/NSException.m: Don't add stacktrace information if we are not building with debug on. + * Source/GSString.m: Minor optimisation ... return @"" for all + substrings with a zero length range. 2006-05-22 Richard Frith-Macdonald diff --git a/Source/GSString.m b/Source/GSString.m index f5f22b33b..145d771bd 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -2455,6 +2455,10 @@ substring_c(GSStr self, NSRange aRange) @defs(GSCSubString) } *o; + if (aRange.length == 0) + { + return @""; + } o = (typeof(o))NSAllocateObject(GSCSubStringClass, 0, NSDefaultMallocZone()); o->_contents.c = self->_contents.c + aRange.location; @@ -2473,6 +2477,10 @@ substring_u(GSStr self, NSRange aRange) @defs(GSUnicodeSubString) } *o; + if (aRange.length == 0) + { + return @""; + } o = (typeof(o))NSAllocateObject(GSUnicodeSubStringClass, 0, NSDefaultMallocZone()); o->_contents.u = self->_contents.u + aRange.location; @@ -4127,6 +4135,10 @@ agree, create a new GSUnicodeInlineString otherwise. { GS_RANGE_CHECK(aRange, _count); + if (aRange.length == 0) + { + return @""; + } if (_flags.wide == 1) { struct { @@ -4164,6 +4176,10 @@ agree, create a new GSUnicodeInlineString otherwise. { GS_RANGE_CHECK(aRange, _count); + if (aRange.length == 0) + { + return @""; + } if (_flags.wide == 1) { struct {