Skip to content

Commit

Permalink
Remove commented out code and redundant comments from std.experimenta…
Browse files Browse the repository at this point in the history
…l.allocator
  • Loading branch information
JackStouffer committed May 12, 2016
1 parent e378f3e commit c643eaa
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 113 deletions.
6 changes: 2 additions & 4 deletions std/experimental/allocator/building_blocks/allocator_list.d
Expand Up @@ -102,7 +102,7 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator)
// State is stored in an array, but it has a list threaded through it by
// means of "nextIdx".

// state {
// state
static if (!ouroboros)
{
static if (stateSize!BookkeepingAllocator) BookkeepingAllocator bkalloc;
Expand All @@ -114,7 +114,6 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator)
}
private Node[] allocators;
private Node* root;
// }

static if (stateSize!Factory)
{
Expand Down Expand Up @@ -228,10 +227,9 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator)
}
auto toFree = allocators;

// Change state {
// Change state
root = newAllocators.ptr + (root - allocators.ptr);
allocators = newAllocators;
// }

// Free the olden buffer
static if (ouroboros)
Expand Down
25 changes: 0 additions & 25 deletions std/experimental/allocator/building_blocks/bitmapped_block.d
Expand Up @@ -259,7 +259,6 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment
@trusted void[] allocate(const size_t s)
{
const blocks = s.divideRoundUp(blockSize);
//writefln("Allocating %s blocks each of size %s", blocks, blockSize);
void[] result = void;

switcharoo:
Expand Down Expand Up @@ -467,22 +466,6 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment
_control[i .. i + blocks] = 1;
return _payload[cast(size_t) (i * blockSize)
.. cast(size_t) ((i + blocks) * blockSize)];
//void[] result;
//auto pos = tuple(_startIdx, 0);
//for (;;)
//{
// if (pos[0] >= _control.rep.length)
// {
// // No more memory
// return null;
// }
// pos = allocateAt(pos[0], pos[1], blocks, result);
// if (pos[0] == size_t.max)
// {
// // Found and allocated
// return result;
// }
//}
}

// Rounds sizeInBytes to a multiple of blockSize.
Expand Down Expand Up @@ -534,7 +517,6 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment
assert((b.ptr - _payload.ptr) % blockSize == 0);
const blockIdx = (b.ptr - _payload.ptr) / blockSize;
const blockIdxAfter = blockIdx + blocksOld;
//writefln("blockIdx: %s, blockIdxAfter: %s", blockIdx, blockIdxAfter);

// Try the maximum
const wordIdx = blockIdxAfter / 64,
Expand Down Expand Up @@ -601,8 +583,6 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment
bool deallocate(void[] b)
{
if (b is null) return true;
// Adjust pointer, might be inside a block after alignedAllocate
//auto p = (b.ptr - _payload.ptr) / blockSize

// Locate position
immutable pos = b.ptr - _payload.ptr;
Expand Down Expand Up @@ -753,8 +733,6 @@ unittest
text(x.ptr, " ", x.length, " ", a));
a.deallocateAll();

//writeln("Control words: ", a._control.length);
//writeln("Payload bytes: ", a._payload.length);
bool twice = true;

begin:
Expand Down Expand Up @@ -852,7 +830,6 @@ unittest
BitmappedBlock!(8, 8, NullAllocator) h1;
assert(h1.totalAllocation(1) >= 8);
assert(h1.totalAllocation(64) >= 64);
//writeln(h1.totalAllocation(8 * 64));
assert(h1.totalAllocation(8 * 64) >= 8 * 64);
assert(h1.totalAllocation(8 * 63) >= 8 * 63);
assert(h1.totalAllocation(8 * 64 + 1) >= 8 * 65);
Expand Down Expand Up @@ -1034,8 +1011,6 @@ struct BitmappedBlockWithInternalPointers(
// Find block start
auto block = (p - _heap._payload.ptr) / _heap.blockSize;
if (block >= _allocStart.length) return null;
// This may happen during marking, so comment it out.
// if (!_heap._control[block]) return null;
// Within an allocation, must find the 1 just to the left of it
auto i = _allocStart.find1Backward(block);
if (i == i.max) return null;
Expand Down
10 changes: 1 addition & 9 deletions std/experimental/allocator/building_blocks/bucketizer.d
Expand Up @@ -24,20 +24,12 @@ struct Bucketizer(Allocator, size_t min, size_t max, size_t step)
static assert((max - (min - 1)) % step == 0,
"Invalid limits when instantiating " ~ Bucketizer.stringof);

//static if (min == chooseAtRuntime) size_t _min;
//else alias _min = min;
//static if (max == chooseAtRuntime) size_t _max;
//else alias _max = max;
//static if (step == chooseAtRuntime) size_t _step;
//else alias _step = step;

// state {
// state
/**
The array of allocators is publicly available for e.g. initialization and
inspection.
*/
Allocator[(max + 1 - min) / step] buckets;
// }

private Allocator* allocatorFor(size_t n)
{
Expand Down
10 changes: 3 additions & 7 deletions std/experimental/allocator/building_blocks/free_list.d
Expand Up @@ -165,7 +165,7 @@ struct FreeList(ParentAllocator,
return (cast(void*) p)[0 .. max];
}

// statistics {
// statistics
static if (adaptive == Yes.adaptive)
{
private enum double windowLength = 1000.0;
Expand Down Expand Up @@ -198,12 +198,11 @@ struct FreeList(ParentAllocator,
}
}
}
// } statistics

private struct Node { Node* next; }
static assert(ParentAllocator.alignment >= Node.alignof);

// state {
// state
/**
The parent allocator. Depending on whether $(D ParentAllocator) holds state
or not, this is a member variable or an alias for
Expand All @@ -214,7 +213,6 @@ struct FreeList(ParentAllocator,
private Node* root;
static if (minSize == chooseAtRuntime) private size_t _min = chooseAtRuntime;
static if (maxSize == chooseAtRuntime) private size_t _max = chooseAtRuntime;
// }

/**
Alignment offered.
Expand Down Expand Up @@ -392,7 +390,6 @@ unittest
FreeList!(GCAllocator, 0, 8) fl;
assert(fl.root is null);
auto b1 = fl.allocate(7);
//assert(fl._root !is null);
fl.allocate(8);
assert(fl.root is null);
fl.deallocate(b1);
Expand Down Expand Up @@ -436,7 +433,7 @@ struct ContiguousFreeList(ParentAllocator,

alias SParent = StatsCollector!(ParentAllocator, Options.bytesUsed);

// state {
// state
/**
The parent allocator. Depending on whether $(D ParentAllocator) holds state
or not, this is a member variable or an alias for
Expand All @@ -446,7 +443,6 @@ struct ContiguousFreeList(ParentAllocator,
FreeList!(NullAllocator, minSize, maxSize) fl;
void[] support;
size_t allocated;
// }

/// Alignment offered.
enum uint alignment = (void*).alignof;
Expand Down
3 changes: 1 addition & 2 deletions std/experimental/allocator/building_blocks/free_tree.d
Expand Up @@ -54,11 +54,10 @@ struct FreeTree(ParentAllocator)
import std.algorithm : min, max, swap;
import std.traits : hasMember;

// State {
// State
static if (stateSize!ParentAllocator) private ParentAllocator parent;
else private alias parent = ParentAllocator.instance;
private Node* root; // that's the entire added state
// }

private struct Node
{
Expand Down
Expand Up @@ -149,7 +149,7 @@ struct KRRegion(ParentAllocator = NullAllocator)
}
}

// state {
// state
/**
If $(D ParentAllocator) holds state, $(D parent) is a public member of type
$(D KRRegion). Otherwise, $(D parent) is an $(D alias) for
Expand All @@ -160,7 +160,6 @@ struct KRRegion(ParentAllocator = NullAllocator)
private void[] payload;
private Node* root;
private bool regionMode = true;
// }

auto byNodePtr()
{
Expand Down Expand Up @@ -518,8 +517,6 @@ struct KRRegion(ParentAllocator = NullAllocator)
*/
void[] allocateAll()
{
//debug(KRRegion) assertValid("allocateAll");
//debug(KRRegion) scope(exit) assertValid("allocateAll");
if (regionMode) switchToFreeList;
if (root && root.next == root)
return allocate(root.size);
Expand Down
9 changes: 0 additions & 9 deletions std/experimental/allocator/building_blocks/null_allocator.d
@@ -1,14 +1,5 @@
module std.experimental.allocator.building_blocks.null_allocator;

/*
_ _ _ _ _ _ _
| \ | | | | | /\ | | | | |
| \| |_ _| | | / \ | | | ___ ___ __ _| |_ ___ _ __
| . ` | | | | | | / /\ \ | | |/ _ \ / __/ _` | __/ _ \| '__|
| |\ | |_| | | |/ ____ \| | | (_) | (_| (_| | || (_) | |
|_| \_|\__,_|_|_/_/ \_\_|_|\___/ \___\__,_|\__\___/|_|
*/

/**
$(D NullAllocator) is an emphatically empty implementation of the allocator
interface. Although it has no direct use, it is useful as a "terminator" in
Expand Down
12 changes: 2 additions & 10 deletions std/experimental/allocator/building_blocks/region.d
Expand Up @@ -34,7 +34,7 @@ struct Region(ParentAllocator = NullAllocator,

import std.traits : hasMember;

// state {
// state
/**
The _parent allocator. Depending on whether $(D ParentAllocator) holds state
or not, this is a member variable or an alias for
Expand All @@ -49,7 +49,6 @@ struct Region(ParentAllocator = NullAllocator,
alias parent = ParentAllocator.instance;
}
private void* _current, _begin, _end;
// }

/**
Constructs a region backed by a user-provided store. Assumes $(D store) is
Expand Down Expand Up @@ -88,10 +87,9 @@ struct Region(ParentAllocator = NullAllocator,
}

/*
TODO: The postblit of $(D BasicRegion) is disabled because such objects
TODO: The postblit of $(D BasicRegion) should be disabled because such objects
should not be copied around naively.
*/
//@disable this(this);

/**
If `ParentAllocator` is not `NullAllocator` and defines `deallocate`, the region defines a destructor that uses `ParentAllocator.delete` to free the
Expand Down Expand Up @@ -425,12 +423,6 @@ struct InSituRegion(size_t size, size_t minAlign = platformAlignment)
private void lazyInit()
{
assert(!_impl._current);
//static if (alignment > double.alignof)
//{
// auto p = _store.ptr.alignUpTo(alignment);
//}
//else
// auto p = _store.ptr;
_impl = typeof(_impl)(_store);
assert(_impl._current.alignedAt(alignment));
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ struct ScopedAllocator(ParentAllocator)

alias Allocator = AffixAllocator!(ParentAllocator, Node);

// state {
// state
/**
If $(D ParentAllocator) is stateful, $(D parent) is a property giving access
to an $(D AffixAllocator!ParentAllocator). Otherwise, $(D parent) is an alias for `AffixAllocator!ParentAllocator.instance`.
Expand All @@ -48,7 +48,6 @@ struct ScopedAllocator(ParentAllocator)
alias parent = Allocator.instance;
}
private Node* root;
// }

/**
$(D ScopedAllocator) is not copyable.
Expand Down
7 changes: 0 additions & 7 deletions std/experimental/allocator/building_blocks/segregator.d
Expand Up @@ -256,7 +256,6 @@ struct Segregator(size_t threshold, SmallAllocator, LargeAllocator)
&& !stateSize!LargeAllocator
&& is(typeof(SmallAllocator.instance) == shared)
&& is(typeof(LargeAllocator.instance) == shared);
//pragma(msg, sharedMethods);

static if (sharedMethods)
{
Expand Down Expand Up @@ -336,12 +335,6 @@ template Segregator(Args...) if (Args.length > 3)
.Segregator!(Args[2 .. $])
);
}

// Linear search
//alias Segregator = .Segregator!(
// Args[0], Args[1],
// .Segregator!(Args[2 .. $])
//);
}

///
Expand Down
4 changes: 0 additions & 4 deletions std/experimental/allocator/building_blocks/stats_collector.d
Expand Up @@ -702,10 +702,6 @@ unittest
assert(a.numDeallocate == 3);
assert(a.numAllocate == a.numDeallocate);
assert(a.bytesUsed == 0);

//import std.stdio;
//Allocator.reportPerCallStatistics(stdout);
//a.reportStatistics(stdout);
}

import std.experimental.allocator.gc_allocator : GCAllocator;
Expand Down
26 changes: 0 additions & 26 deletions std/experimental/allocator/common.d
Expand Up @@ -493,32 +493,6 @@ package bool isGoodDynamicAlignment(uint x)
return x.isPowerOf2 && x >= (void*).sizeof;
}

/*
If $(D b.length + delta <= a.goodAllocSize(b.length)), $(D expand) just adjusts
$(D b) and returns $(D true). Otherwise, returns $(D false).
$(D expand) does not attempt to use $(D Allocator.reallocate) even if
defined. This is deliberate so allocators may use it internally within their own
implementation of $(D expand).
*/
//bool expand(Allocator)(ref Allocator a, ref void[] b, size_t delta)
//{
// if (!b.ptr)
// {
// b = a.allocate(delta);
// return b.length == delta;
// }
// if (delta == 0) return true;
// immutable length = b.length + delta;
// if (length <= a.goodAllocSize(b.length))
// {
// b = b.ptr[0 .. length];
// return true;
// }
// return false;
//}

/**
The default $(D reallocate) function first attempts to use $(D expand). If $(D
Allocator.expand) is not defined or returns $(D false), $(D reallocate)
Expand Down
5 changes: 1 addition & 4 deletions std/experimental/allocator/typed.d
Expand Up @@ -141,14 +141,11 @@ struct TypedAllocator(PrimaryAllocator, Policies...)
}
}

// state {
// state
static if (stateSize!PrimaryAllocator) private PrimaryAllocator primary;
else alias primary = PrimaryAllocator.instance;
static if (Policies.length > 0)
private Tuple!(Stride2!(Policies[1 .. $])) extras;
// }

//pragma(msg, "Allocators available: ", typeof(extras));

private static bool match(uint have, uint want)
{
Expand Down

0 comments on commit c643eaa

Please sign in to comment.