Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/core/bitop.d
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,32 @@ struct BitRange
}
}

/**
* Construct a BitRange.
*
* Params:
* bitarr = The array of bits to iterate over
* numBits = The total number of valid bits in the given bit array
* startBit = The initial start index to start searching
*/
this(const(size_t)* bitarr, size_t numBits, size_t startBit) @system
{
assert(startBit <= numBits);
bits = bitarr;
len = numBits;
idx = startBit;
if (len)
{
bits += idx / bitsPerWord;
auto curbit = idx % bitsPerWord;
// prime the first bit
cur = *bits++ ^ (size_t(1) << curbit);
if (curbit)
cur &= ~((size_t(1) << curbit) - 1); // clear skipped lower bits
popFront();
}
}

/// Range functions
size_t front()
{
Expand Down Expand Up @@ -453,6 +479,11 @@ struct BitRange
bts(bitArr, 95);
bts(bitArr, 78);

assert(BitRange(bitArr, 100).front() == 24);

bts(bitArr, 0);
assert(BitRange(bitArr, 100).front() == 0);

enum sum = 48 + 24 + 95 + 78;

// iterate
Expand All @@ -465,7 +496,10 @@ struct BitRange
}

assert(testSum == sum);
assert(nBits == 4);
assert(nBits == 5);

assert(BitRange(bitArr, 100, 50).front() == 78);
assert(BitRange(bitArr, 100, 48).front() == 48);
}

@system unittest
Expand Down
23 changes: 22 additions & 1 deletion src/core/memory.d
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
* happens and there is insufficient _memory available.)
* )
*
* Copyright: Copyright Sean Kelly 2005 - 2015.
* Copyright: Copyright Sean Kelly 2005 - 2016.
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Authors: Sean Kelly, Alex Rønne Petersen
* Source: $(DRUNTIMESRC core/_memory.d)
Expand Down Expand Up @@ -126,6 +126,7 @@ private
extern (C) size_t gc_extend( void* p, size_t mx, size_t sz, const TypeInfo = null ) pure nothrow;
extern (C) size_t gc_reserve( size_t sz ) nothrow;
extern (C) void gc_free( void* p ) pure nothrow @nogc;
extern (C) bool gc_emplace( void *p, size_t len, const TypeInfo ti ) pure nothrow;

extern (C) void* gc_addrOf( void* p ) pure nothrow @nogc;
extern (C) size_t gc_sizeOf( void* p ) pure nothrow @nogc;
Expand Down Expand Up @@ -260,6 +261,10 @@ struct GC
NO_INTERIOR = 0b0001_0000,

STRUCTFINAL = 0b0010_0000, // the block has a finalizer for (an array of) structs

// additional info for allocating with type info
NO_RTINFO = 0b0100_0000, // do not copy RTInfo in malloc/realloc
REP_RTINFO = 0b1000_0000, // repeat RTInfo if allocation is larger than type info
}


Expand Down Expand Up @@ -680,6 +685,22 @@ struct GC
return gc_stats();
}

/**
* Describe the memory at the given address range for precise collection
*
* Params:
* p = A pointer to the root or the interior of a valid memory block
* len = Length of the memory range
* ti = Type info describing the memory usage
*
* Returns:
* true if p points to GC managed memory
*/
static bool emplace( void *p, size_t len, const TypeInfo ti ) pure nothrow
{
return gc_emplace( p, len, ti );
}

/**
* Adds an internal root pointing to the GC memory block referenced by p.
* As a result, the block referenced by p itself and any blocks accessible
Expand Down
Loading