Changeset 6f7aff3 for tests


Ignore:
Timestamp:
Oct 19, 2021, 10:31:53 AM (3 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
fe18b46
Parents:
7b0e8b7
Message:

String hybrid assignment to unshared now optimizes to overwrite instead of copy.

Location:
tests/collections
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/collections/string-api-coverage.cfa

    r7b0e8b7 r6f7aff3  
    11#include <containers/string.hfa>
     2#include <string_sharectx.hfa>
    23
    34void assertWellFormedHandleList( int maxLen ) { // with(HeapArea)
     
    2526
    2627int main () {
     28
     29    #ifdef STRING_SHARING_OFF
     30    sout | "string sharing disabled";
     31    string_sharectx c = { NO_SHARING };
     32    #endif
     33
    2734    string s = "hello";
    2835    string s2 = "hello";
  • tests/collections/string-ctx-manage.cfa

    r7b0e8b7 r6f7aff3  
    33#include <string_res.hfa>
    44
     5// In these tests, shared heaps are never remotely full and string sizes are tiny.
     6// So here, the SUT should put a yes-sharing string in a heap with lots of spare room.
     7// The SUT should always keep a no-sharing string's buffer 1x--2x the string's size.
     8// This check uses 3x as a heuristic split between those cases.
     9void assertSpareRoomInHeap( string & s, bool expectOversized ) {
     10    double bytesInHeap = DEBUG_string_bytes_in_heap(s.inner->Handle.ulink);
     11    double bytesUsed =  s.inner->Handle.lnth;
     12    double overhead = bytesInHeap / bytesUsed;
     13    assert (overhead >= 1);
     14    if ( expectOversized )
     15        assert( overhead >= 3.0 );
     16    else
     17        assert( overhead < 3.0 );
     18}
     19
    520void baseline() {
    621    string x = "hi";
     22    assertSpareRoomInHeap( x, true );
    723
    824    string y = x; // construct y in same context, no write yet => no copy yet
     25    assertSpareRoomInHeap( y, true );
    926    assert( y.inner->Handle.s == x.inner->Handle.s);
    1027    sout | y; // hi
    1128
    1229    x = "bye";
     30    assertSpareRoomInHeap( x, true );
    1331    y = x; // y in same context, no write yet => no copy yet
     32    assertSpareRoomInHeap( y, true );
    1433    assert( y.inner->Handle.s == x.inner->Handle.s);
    1534    sout | y; // bye
     
    1837void eagerCopy() {
    1938    string x = "hi";
     39    assertSpareRoomInHeap( x, true );
    2040    string_sharectx c = { NEW_SHARING };
    2141
    2242    string y = x; // construct y in different context => eager copy
     43    assertSpareRoomInHeap( y, true );
    2344    assert( y.inner->Handle.s != x.inner->Handle.s);
    2445    sout | y; // hi
    2546
    2647    x = "bye";
     48    assertSpareRoomInHeap( x, true );
    2749    y = x; // y was already in different context => eager copy
     50    assertSpareRoomInHeap( y, true );
    2851    assert( y.inner->Handle.s != x.inner->Handle.s);
    2952    sout | y; // bye
     
    3255void soloAlloc() {
    3356    string x = "hi";
     57    assertSpareRoomInHeap( x, true );
    3458    string_sharectx c = { NO_SHARING };
    3559   
    3660    string y = x; // y allocates into private pad, implying eager copy
     61    assertSpareRoomInHeap( y, false );
    3762    assert( y.inner->Handle.s != x.inner->Handle.s);
    38     assert( DEBUG_string_bytes_in_heap(y.inner->Handle.ulink) == y.inner->Handle.lnth );  // y is in a perfectly fitting heap
    3963    sout | y; // hi
    4064
    4165    x = "bye";
     66    assertSpareRoomInHeap( x, true );
    4267    y = x; // into private y => eager copy
     68    assertSpareRoomInHeap( y, false );
    4369    assert( y.inner->Handle.s != x.inner->Handle.s);
    44 //    assert( DEBUG_string_bytes_in_heap(y.inner->Handle.ulink) == y.inner->Handle.lnth );  // optimization required
    4570    sout | y; // bye
    4671}
Note: See TracChangeset for help on using the changeset viewer.