Coverage Report

Created: 2018-07-03 15:31

/home/travis/build/MoarVM/MoarVM/src/core/intcache.c
Line
Count
Source
1
#include "moar.h"
2
3
307
void MVM_intcache_for(MVMThreadContext *tc, MVMObject *type) {
4
307
    int type_index;
5
307
    int right_slot = -1;
6
307
    uv_mutex_lock(&tc->instance->mutex_int_const_cache);
7
309
    for (type_index = 0; type_index < 4; type_index++) {
8
309
        if (tc->instance->int_const_cache->types[type_index] == NULL) {
9
146
            right_slot = type_index;
10
146
            break;
11
146
        }
12
163
        else if (tc->instance->int_const_cache->types[type_index] == type) {
13
161
            uv_mutex_unlock(&tc->instance->mutex_int_const_cache);
14
161
            return;
15
161
        }
16
309
    }
17
146
    if (right_slot != -1) {
18
146
        int val;
19
2.48k
        for (val = -1; val < 15; val++) {
20
2.33k
            MVMObject *obj;
21
2.33k
            obj = MVM_repr_alloc_init(tc, type);
22
2.33k
            MVM_repr_set_int(tc, obj, val);
23
2.33k
            tc->instance->int_const_cache->cache[type_index][val + 1] = obj;
24
2.33k
            MVM_gc_root_add_permanent_desc(tc,
25
2.33k
                (MVMCollectable **)&tc->instance->int_const_cache->cache[type_index][val + 1],
26
2.33k
                "Boxed integer cache entry");
27
2.33k
        }
28
146
        tc->instance->int_const_cache->types[type_index] = type;
29
146
        MVM_gc_root_add_permanent_desc(tc,
30
146
            (MVMCollectable **)&tc->instance->int_const_cache->types[type_index],
31
146
            "Boxed integer cache type");
32
146
    }
33
146
    uv_mutex_unlock(&tc->instance->mutex_int_const_cache);
34
146
}
35
36
10.8M
MVMObject *MVM_intcache_get(MVMThreadContext *tc, MVMObject *type, MVMint64 value) {
37
10.8M
    int type_index;
38
10.8M
    int right_slot = -1;
39
10.8M
40
10.8M
    if (value < -1 || value >= 15)
41
6.60M
        return NULL;
42
10.8M
43
4.21M
    for (type_index = 0; type_index < 4; type_index++) {
44
4.21M
        if (tc->instance->int_const_cache->types[type_index] == type) {
45
4.21M
            right_slot = type_index;
46
4.21M
            break;
47
4.21M
        }
48
4.21M
    }
49
4.21M
    if (right_slot != -1) {
50
4.21M
        return tc->instance->int_const_cache->cache[right_slot][value + 1];
51
4.21M
    }
52
351
    return NULL;
53
4.21M
}