summaryrefslogtreecommitdiffstats
path: root/src/video_core/buffer_cache/map_interval.cpp
blob: 62587e18a1c186d644dd890d83e5f69c8e1e7534 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <algorithm>
#include <array>
#include <cstddef>
#include <memory>

#include "video_core/buffer_cache/map_interval.h"

namespace VideoCommon {

MapIntervalAllocator::MapIntervalAllocator() {
    FillFreeList(first_chunk);
}

MapIntervalAllocator::~MapIntervalAllocator() = default;

void MapIntervalAllocator::AllocateNewChunk() {
    *new_chunk = std::make_unique<Chunk>();
    FillFreeList(**new_chunk);
    new_chunk = &(*new_chunk)->next;
}

void MapIntervalAllocator::FillFreeList(Chunk& chunk) {
    const std::size_t old_size = free_list.size();
    free_list.resize(old_size + chunk.data.size());
    std::transform(chunk.data.rbegin(), chunk.data.rend(), free_list.begin() + old_size,
                   [](MapInterval& interval) { return &interval; });
}

} // namespace VideoCommon