ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/GList.hh
(Generate patch)
# Line 492 | Line 492
492          newList[idx]=item;
493          //copy data after idx
494          //memmove(&newList[idx+1],&fArray[idx], (fCount-idx)*sizeof(OBJ));
495 <        for (int i=idx+1;i<fCount;i++) {
495 >        for (int i=idx+1;i<=fCount;i++) {
496            newList[i]=fArray[i-1];
497            }
498          //memset(&newList[fCount+1], 0, (NewCapacity-fCount-1)*sizeof(OBJ));
# Line 630 | Line 630
630   //so the allowed range is [0..fCount]
631   //the old idx item all the above will be shifted to idx+1
632   if (idx<0 || idx>fCount) GError(SLISTINDEX_ERR, idx);
633 < if (fCount==fCapacity) { //need to resize
634 <    Grow(idx, item);
635 <    //expand and also copy/move data and insert the new item
633 > if (fCount==fCapacity) { //need to resize the array
634 >    Grow(idx, item); //expand and also copy/move data and insert the new item
635      return;
636      }
637   //move data around to make room for the new item
638 < if (idx<fCount)
639 <      memmove(&fArray[idx+1], &fArray[idx], (fCount-idx)*sizeof(OBJ));
638 > if (idx<fCount) {
639 >      //copy after-idx items (shift up)
640 >      //memmove(&newList[idx+1],&fArray[idx], (fCount-idx)*sizeof(OBJ));
641 >      for (int i=fCount; i>idx; i--) {
642 >          fArray[i]=fArray[i-1];
643 >          }
644 >      }
645   fArray[idx]=item;
646   fCount++;
647   }
# Line 697 | Line 701
701  
702   template <class OBJ> void GVec<OBJ>::Delete(int index) {
703   TEST_INDEX(index);
700 //fArray[index]=NULL;
704   fCount--;
705 < if (index<fCount) //move higher elements if any
706 <   memmove(&fArray[index], &fArray[index+1], (fCount-index)*sizeof(OBJ));
705 > while (index<fCount) {
706 >    //move higher elements if any (shift down)
707 >    //memmove(&fArray[index], &fArray[index+1], (fCount-index)*sizeof(OBJ));
708 >    fArray[index]=fArray[index+1];
709 >    index++;
710 >    }
711   }
712  
713   template <class OBJ> void GVec<OBJ>::setCount(int NewCount) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines