gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mutableCopy in NSArray


From: Richard Frith-Macdonald
Subject: Re: mutableCopy in NSArray
Date: Tue, 19 Mar 2002 09:46:06 +0000

On Monday, March 18, 2002, at 08:25 PM, Thorano wrote:



RFM> GNUstep copying of container classes like NSArray follows the same rules
RFM> as MacOS-X ... for compatibility.

RFM> A mutable copy is *not* supposed to be a deep copy, rather
RFM> it's suppose supposed to produce a new container which can be modified
RFM> without affecting he original container - note, it's a copy of the
RFM> container, not its contents.


ok, I understand the spirit. But in this case [NSMutableArray copyWithZone]
is wrong :

- (id) copyWithZone: (NSZone*)zone
{
  /* a deep copy */
  unsigned      count = [self count];
  id            objects[count];
  NSArray       *newArray;
  unsigned      i;

  [self getObjects: objects];
  for (i = 0; i < count; i++)
    objects[i] = [objects[i] copyWithZone: zone];
  newArray = [[GSArrayClass allocWithZone: zone]
    initWithObjects: objects count: count];
  while (i > 0)
    RELEASE(objects[--i]);
  return newArray;
}

unless there is a something else I don't understand.

A copy does not do the same thing as a mutable copy...

OpenStep does not mandate a particular behavior for copy and
mutable copy ... so we just do what OPENSTEP and now MacOS-X do
so we have compatibility.

The best thing to do is run a test program on MacOS-X to check
it's behavior, and then check to see that GNUstep does the
same thing ... it should.

Of course, it's possible that Apple have quietly changed things ...
so it's good to check every once in a while.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]