<commit_before>package io.apptik.comm.jus.util;


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.LruCache;

import java.util.Map;
import java.util.Set;
import java.util.UUID;


/**
 * True pooled Bitmap Cache. It works as follows.
 *
 * BitmapLruCache gets full --> overflowed bitmaps goes to the BitmapLruPool
 * BitmapLruPool gets full --> overflowed bitmaps goes to the SoftRef reusable Bitmap Set
 *
 */
public class PooledBitmapLruCache extends DefaultBitmapLruCache {

    LruCache<String, Bitmap> bPool;

    public PooledBitmapLruCache() {
        this(getDefaultLruCacheSize());
    }

    public PooledBitmapLruCache(int maxSize) {
        super(maxSize);
        bPool = new LruCache<String, Bitmap>(maxSize) {
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return PooledBitmapLruCache.super.sizeOf(key, value);
            }

            @Override
            protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap
                    newValue) {
                //passes to the soft ref set
                PooledBitmapLruCache.super.addToPool(oldValue);
            }
        };
    }

    public LruCache<String, Bitmap> pool() {
        return bPool;
    }

    public void preFill(int w, int h) {
        int fill = size();
        Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        int size = getBitmapSize(bmp) / 1024;
        addToPool(bmp);
        fill+=size;
        while (fill<maxSize()) {
            addToPool(Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888));
            fill+=size;
        }
    }

    @Override
    public synchronized Bitmap getReusableBitmap(BitmapFactory.Options options) {
        Set<Map.Entry<String, Bitmap>> bitmaps = bPool.snapshot().entrySet();
        Bitmap bitmap = null;

        if (bitmaps != null && !bitmaps.isEmpty()) {
            for (Map.Entry<String, Bitmap> bmpEntry : bitmaps) {
                Bitmap item = bmpEntry.getValue();
                if (null != item && item.isMutable()) {
                    // Check to see it the item can be used for inBitmap
                    if (canUseForInBitmap(item, options)) {
                        bitmap = item;
                        // Remove from reusable set so it can't be used again
                        bPool.remove(bmpEntry.getKey());
                        break;
                    }
                } else {
                    // Remove from the set if the reference has been cleared.
                    bPool.remove(bmpEntry.getKey());
                }
            }
        }

        if (bitmap != null) {
            return bitmap;
        } else {
            return super.getReusableBitmap(options);
        }
    }

    /**
     * adds bitmap to the LRU pool. If limit is reached value will be thrown at
     * {@link LruCache#entryRemoved(boolean, Object, Object, Object)} where it will be handled by
     * {@link DefaultBitmapLruCache#addToPool(Bitmap)}.
     */
    @Override
    public synchronized void addToPool(Bitmap bitmap) {
        bPool.put(UUID.randomUUID().toString(), bitmap);
    }
}
<commit_msg>bmp pool / imagerequest fix<commit_after>package io.apptik.comm.jus.util;


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.LruCache;

import java.util.Map;
import java.util.Set;
import java.util.UUID;


/**
 * True pooled Bitmap Cache. It works as follows.
 *
 * BitmapLruCache gets full --> overflowed bitmaps goes to the BitmapLruPool
 * BitmapLruPool gets full --> overflowed bitmaps goes to the SoftRef reusable Bitmap Set
 *
 */
public class PooledBitmapLruCache extends DefaultBitmapLruCache {

    LruCache<String, Bitmap> bPool;

    public PooledBitmapLruCache() {
        this(getDefaultLruCacheSize());
    }

    public PooledBitmapLruCache(int maxSize) {
        super(maxSize);
        bPool = new LruCache<String, Bitmap>(maxSize) {
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return PooledBitmapLruCache.super.sizeOf(key, value);
            }

            @Override
            protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap
                    newValue) {
                //passes to the soft ref set
                PooledBitmapLruCache.super.addToPool(oldValue);
            }
        };
    }

    public LruCache<String, Bitmap> pool() {
        return bPool;
    }

    public void preFill(int w, int h) {
        int fill = size();
        Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        int size = getBitmapSize(bmp) / 1024;
        addToPool(bmp);
        fill+=size;
        while (fill<maxSize()) {
            addToPool(Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888));
            fill+=size;
        }
    }

    @Override
    public synchronized Bitmap getReusableBitmap(BitmapFactory.Options options) {
        Set<Map.Entry<String, Bitmap>> bitmaps = bPool.snapshot().entrySet();
        Bitmap bitmap = null;

        if (bitmaps != null && !bitmaps.isEmpty()) {
            for (Map.Entry<String, Bitmap> bmpEntry : bitmaps) {
                Bitmap item = bmpEntry.getValue();
                if (null != item && item.isMutable()) {
                    // Check to see it the item can be used for inBitmap
                    if (canUseForInBitmap(item, options)) {
                        bitmap = item;
                        // Remove from reusable set so it can't be used again
                        bPool.remove(bmpEntry.getKey());
                        break;
                    }
                } else {
                    // Remove from the set if the reference has been cleared.
                    bPool.remove(bmpEntry.getKey());
                }
            }
        }

        if (bitmap != null) {
            return bitmap;
        } else {
            return super.getReusableBitmap(options);
        }
    }

    /**
     * adds bitmap to the LRU pool. If limit is reached value will be thrown at
     * {@link LruCache#entryRemoved(boolean, Object, Object, Object)} where it will be handled by
     * {@link DefaultBitmapLruCache#addToPool(Bitmap)}.
     */
    @Override
    public synchronized void addToPool(Bitmap bitmap) {
        if (bitmap.isMutable() && !bitmap.isRecycled()) {
            bPool.put(UUID.randomUUID().toString(), bitmap);
        }
    }
}

{'fraction_non_alphanumeric': 0.09636699507389163, 'fraction_numerical': 0.003694581280788177, 'mean_word_length': 1.8978590544157004, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '4445197', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1756, 'n_words': 476}