<commit_before>package jadx.core.dex.info;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.jetbrains.annotations.Nullable;

import jadx.api.JadxArgs;
import jadx.core.dex.attributes.AType;
import jadx.core.dex.instructions.args.LiteralArg;
import jadx.core.dex.instructions.args.PrimitiveType;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.DexNode;
import jadx.core.dex.nodes.FieldNode;
import jadx.core.dex.nodes.parser.FieldInitAttr;
import jadx.core.utils.ErrorsCounter;

public class ConstStorage {

	private static final class ValueStorage {
		private final Map<Object, FieldNode> values = new HashMap<>();
		private final Set<Object> duplicates = new HashSet<>();

		public Map<Object, FieldNode> getValues() {
			return values;
		}

		public FieldNode get(Object key) {
			return values.get(key);
		}

		/**
		 * @return true if this value is duplicated
		 */
		public boolean put(Object value, FieldNode fld) {
			FieldNode prev = values.put(value, fld);
			if (prev != null) {
				values.remove(value);
				duplicates.add(value);
				return true;
			}
			if (duplicates.contains(value)) {
				values.remove(value);
				return true;
			}
			return false;
		}

		public boolean contains(Object value) {
			return duplicates.contains(value) || values.containsKey(value);
		}

		void removeForCls(ClassNode cls) {
			Iterator<Entry<Object, FieldNode>> it = values.entrySet().iterator();
			while (it.hasNext()) {
				Entry<Object, FieldNode> entry = it.next();
				FieldNode field = entry.getValue();
				if (field.getParentClass().equals(cls)) {
					it.remove();
					duplicates.remove(entry.getKey());
				}
			}
		}
	}

	private final boolean replaceEnabled;
	private final ValueStorage globalValues = new ValueStorage();
	private final Map<ClassNode, ValueStorage> classes = new HashMap<>();
<commit_msg>core: ConstStorage: Don't put known duplicate value to ValueStorage.values map<commit_after>package jadx.core.dex.info;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.jetbrains.annotations.Nullable;

import jadx.api.JadxArgs;
import jadx.core.dex.attributes.AType;
import jadx.core.dex.instructions.args.LiteralArg;
import jadx.core.dex.instructions.args.PrimitiveType;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.DexNode;
import jadx.core.dex.nodes.FieldNode;
import jadx.core.dex.nodes.parser.FieldInitAttr;
import jadx.core.utils.ErrorsCounter;

public class ConstStorage {

	private static final class ValueStorage {
		private final Map<Object, FieldNode> values = new HashMap<>();
		private final Set<Object> duplicates = new HashSet<>();

		public Map<Object, FieldNode> getValues() {
			return values;
		}

		public FieldNode get(Object key) {
			return values.get(key);
		}

		/**
		 * @return true if this value is duplicated
		 */
		public boolean put(Object value, FieldNode fld) {
			if (duplicates.contains(value)) {
				values.remove(value);
				return true;
			}
			FieldNode prev = values.put(value, fld);
			if (prev != null) {
				values.remove(value);
				duplicates.add(value);
				return true;
			}
			return false;
		}

		public boolean contains(Object value) {
			return duplicates.contains(value) || values.containsKey(value);
		}

		void removeForCls(ClassNode cls) {
			Iterator<Entry<Object, FieldNode>> it = values.entrySet().iterator();
			while (it.hasNext()) {
				Entry<Object, FieldNode> entry = it.next();
				FieldNode field = entry.getValue();
				if (field.getParentClass().equals(cls)) {
					it.remove();
					duplicates.remove(entry.getKey());
				}
			}
		}
	}

	private final boolean replaceEnabled;
	private final ValueStorage globalValues = new ValueStorage();
	private final Map<ClassNode, ValueStorage> classes = new HashMap<>();

{'fraction_non_alphanumeric': 0.12322274881516587, 'fraction_numerical': 0.0, 'mean_word_length': 4.134443021766965, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '5105635', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1270, 'n_words': 297}