Bug 404638

Summary: Add VG_(replaceIndexXA)
Product: [Developer tools] valgrind Reporter: Łukasz Marek <lukasz.m.luki2>
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: wishlist CC: philippe.waroquiers
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: patch

Description Łukasz Marek 2019-02-21 09:24:33 UTC
Created attachment 118247 [details]
patch

VG_(replaceIndexXA) I found useful for myself manipulating huge array that has around 100k elements and I have to replace some part of them periodically. This allows avoiding elements shifting each time old element is removed when there is a possibility to just replace it with a new one.
Comment 1 Julian Seward 2019-02-21 09:30:24 UTC
Is this actually necessary?  I've always done this:

  T* p = (T*)VG_(indexXA)(arr, index);
  *p = new_value;
Comment 2 Julian Seward 2019-02-21 09:33:01 UTC
or even 

   *(T*)VG_(indexXA)(arr, index) = new_value;

which removes the possibility of the array being modified between the 
call to VG_(indexXA) and the assignment.
Comment 3 Łukasz Marek 2019-02-21 15:06:11 UTC
(In reply to Julian Seward from comment #1)
> Is this actually necessary?  I've always done this:
> 
>   T* p = (T*)VG_(indexXA)(arr, index);
>   *p = new_value;

You are right, this new function is not necessary.
Comment 4 Łukasz Marek 2019-02-21 15:57:58 UTC
Just one remark. Your method doesn't mark array sorted=false. I can live with that anyway.
Comment 5 Julian Seward 2019-02-22 10:12:54 UTC
(In reply to Łukasz Marek from comment #4)
> Just one remark. Your method doesn't mark array sorted=false. I can live
> with that anyway.

Hmm, actually that's a good point.  We do want to set sorted = false in this
case.  So yes, let's keep the function.
Comment 6 Philippe Waroquiers 2019-03-16 11:32:46 UTC
Slightly modified version of the patch pushed as 081c34ea477.
(I have removed some of the asserts and the call to ensureSpace
as the replace operation can never make the array grow.

Thanks for the patch