Line data Source code
1 : // Copyright (C) 2016 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.patch; 16 : 17 : import com.google.common.cache.Weigher; 18 : 19 : /** Computes memory usage for {@link DiffSummary} in bytes of memory used. */ 20 152 : public class DiffSummaryWeigher implements Weigher<DiffSummaryKey, DiffSummary> { 21 : 22 : @Override 23 : public int weigh(DiffSummaryKey key, DiffSummary value) { 24 103 : int size = 25 : 16 26 : + 4 * 8 27 : + 2 * 36 // Size of DiffSummaryKey, 64 bit JVM 28 : + 16 29 : + 8 30 : + 2 * 4 // Size of DiffSummary 31 : + 16 32 : + 8; // String[] 33 103 : for (String p : value.getPaths()) { 34 90 : size += 35 : 16 36 : + 8 37 : + 4 * 4 // String 38 : + 16 39 : + 8 40 90 : + p.length() * 2; // char[] 41 90 : } 42 103 : return size; 43 : } 44 : }