<commit_before>package com.bluejay.repository;

import android.text.Spannable;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class ColoredText implements Spannable {
    private final String rawText;
    private final Map<Object, SpanInfo> map;

    public ColoredText(String rawText, long[] colorings) {
        this.rawText = rawText;
        this.map = buildMap(colorings);
    }

    private static Map<Object, SpanInfo> buildMap(long[] colorings) {
        Map<Object, SpanInfo> map = new HashMap<>();
        int spanStart = 0;

        for (int i = 0; i < colorings.length; i++) {
            long coloring = colorings[i];
            int color = getColor(coloring);
            int count = getCount(coloring);

            int spanEnd = spanStart + count;
            Object span = new ForegroundColorSpan(color);
            map.put(span, new SpanInfo(spanStart, spanEnd));
            spanStart = spanEnd;
        }

        return map;
    }

    private static int getColor(long coloring) {
        return (int)(coloring >>> 32);
    }

    private static int getCount(long coloring) {
        return (int)coloring;
    }

    @Override
    public void setSpan(Object o, int i, int i1, int i2) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void removeSpan(Object o) {
        throw new UnsupportedOperationException();
    }

    @Override
    public <T> T[] getSpans(int i, int i1, Class<T> aClass) {
        int start = i, end = i1;
        Class<T> kind = aClass;

        // SpannableString has to worry about sorting the spans based on the SPAN_PRIORITY mask.
        // However, in our case we always use SPAN_INCLUSIVE_EXCLUSIVE, so every span has the same priority.
        // It's okay to leave them in the same order they were inserted.
        List<T> spans = new ArrayList<>();

        // Hack: This is an implementation detail, but as long as you don't remove items from it, a HashMap
        // will hand out entries in the same order you inserted them.
        for (Map.Entry<Object, SpanInfo> entry : this.map.entrySet()) {<commit_msg>[java] [Perf?] Make type of ColoredText.map more specific. Maybe calls weren't getting devirtualized?<commit_after>package com.bluejay.repository;

import android.text.Spannable;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class ColoredText implements Spannable {
    private final String rawText;
    private final HashMap<Object, SpanInfo> map;

    public ColoredText(String rawText, long[] colorings) {
        assert rawText != null;
        assert colorings != null;

        this.rawText = rawText;
        this.map = buildMap(colorings);
    }

    private static HashMap<Object, SpanInfo> buildMap(long[] colorings) {
        HashMap<Object, SpanInfo> map = new HashMap<>();
        int spanStart = 0;

        for (int i = 0; i < colorings.length; i++) {
            long coloring = colorings[i];
            int color = getColor(coloring);
            int count = getCount(coloring);

            int spanEnd = spanStart + count;
            Object span = new ForegroundColorSpan(color);
            map.put(span, new SpanInfo(spanStart, spanEnd));
            spanStart = spanEnd;
        }

        return map;
    }

    private static int getColor(long coloring) {
        return (int)(coloring >>> 32);
    }

    private static int getCount(long coloring) {
        return (int)coloring;
    }

    @Override
    public void setSpan(Object o, int i, int i1, int i2) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void removeSpan(Object o) {
        throw new UnsupportedOperationException();
    }

    @Override
    public <T> T[] getSpans(int i, int i1, Class<T> aClass) {
        int start = i, end = i1;
        Class<T> kind = aClass;

        // SpannableString has to worry about sorting the spans based on the SPAN_PRIORITY mask.
        // However, in our case we always use SPAN_INCLUSIVE_EXCLUSIVE, so every span has the same priority.
        // It's okay to leave them in the same order they were inserted.
        List<T> spans = new ArrayList<>();

        // Hack: This is an implementation detail, but as long as you don't remove items from it, a HashMap
        // will hand out entries in the same order you inserted them.
        for (HashMap.Entry<Object, SpanInfo> entry : this.map.entrySet()) {
{'fraction_non_alphanumeric': 0.09373034179073181, 'fraction_numerical': 0.003355001048437828, 'mean_word_length': 2.635670731707317, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3403722', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1344, 'n_words': 462}