1.1 --- a/src/share/vm/utilities/growableArray.hpp Thu Aug 01 03:44:03 2019 +0100 1.2 +++ b/src/share/vm/utilities/growableArray.hpp Mon Aug 12 18:30:40 2019 +0300 1.3 @@ -168,6 +168,10 @@ 1.4 GrowableArray(int initial_size, bool C_heap = false, MEMFLAGS F = mtInternal) 1.5 : GenericGrowableArray(initial_size, 0, C_heap, F) { 1.6 _data = (E*)raw_allocate(sizeof(E)); 1.7 +// Needed for Visual Studio 2012 and older 1.8 +#ifdef _MSC_VER 1.9 +#pragma warning(suppress: 4345) 1.10 +#endif 1.11 for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); 1.12 } 1.13 1.14 @@ -372,6 +376,40 @@ 1.15 void sort(int f(E*,E*), int stride) { 1.16 qsort(_data, length() / stride, sizeof(E) * stride, (_sort_Fn)f); 1.17 } 1.18 + 1.19 + // Binary search and insertion utility. Search array for element 1.20 + // matching key according to the static compare function. Insert 1.21 + // that element is not already in the list. Assumes the list is 1.22 + // already sorted according to compare function. 1.23 + template <int compare(const E&, const E&)> E insert_sorted(const E& key) { 1.24 + bool found; 1.25 + int location = find_sorted<E, compare>(key, found); 1.26 + if (!found) { 1.27 + insert_before(location, key); 1.28 + } 1.29 + return at(location); 1.30 + } 1.31 + 1.32 + template <typename K, int compare(const K&, const E&)> int find_sorted(const K& key, bool& found) { 1.33 + found = false; 1.34 + int min = 0; 1.35 + int max = length() - 1; 1.36 + 1.37 + while (max >= min) { 1.38 + int mid = (int)(((uint)max + min) / 2); 1.39 + E value = at(mid); 1.40 + int diff = compare(key, value); 1.41 + if (diff > 0) { 1.42 + min = mid + 1; 1.43 + } else if (diff < 0) { 1.44 + max = mid - 1; 1.45 + } else { 1.46 + found = true; 1.47 + return mid; 1.48 + } 1.49 + } 1.50 + return min; 1.51 + } 1.52 }; 1.53 1.54 // Global GrowableArray methods (one instance in the library per each 'E' type). 1.55 @@ -385,6 +423,10 @@ 1.56 E* newData = (E*)raw_allocate(sizeof(E)); 1.57 int i = 0; 1.58 for ( ; i < _len; i++) ::new ((void*)&newData[i]) E(_data[i]); 1.59 +// Needed for Visual Studio 2012 and older 1.60 +#ifdef _MSC_VER 1.61 +#pragma warning(suppress: 4345) 1.62 +#endif 1.63 for ( ; i < _max; i++) ::new ((void*)&newData[i]) E(); 1.64 for (i = 0; i < old_max; i++) _data[i].~E(); 1.65 if (on_C_heap() && _data != NULL) {