< prev index next >

src/java.base/share/classes/java/util/BitSet.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 1180,1196 **** * @return a string representation of this bit set */ public String toString() { checkInvariants(); - final int MAX_INITIAL_CAPACITY = Integer.MAX_VALUE - 8; int numBits = (wordsInUse > 128) ? cardinality() : wordsInUse * BITS_PER_WORD; ! // Avoid overflow in the case of a humongous numBits ! int initialCapacity = (numBits <= (MAX_INITIAL_CAPACITY - 2) / 6) ? ! 6 * numBits + 2 : MAX_INITIAL_CAPACITY; ! StringBuilder b = new StringBuilder(initialCapacity); b.append('{'); int i = nextSetBit(0); if (i != -1) { b.append(i); --- 1180,1192 ---- * @return a string representation of this bit set */ public String toString() { checkInvariants(); int numBits = (wordsInUse > 128) ? cardinality() : wordsInUse * BITS_PER_WORD; ! StringBuilder b = new StringBuilder(6*numBits + 2); b.append('{'); int i = nextSetBit(0); if (i != -1) { b.append(i);
< prev index next >