Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: third_party/WebKit/Source/wtf/BitVector.cpp

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 16 matching lines...) Expand all
27 27
28 #include "wtf/LeakAnnotations.h" 28 #include "wtf/LeakAnnotations.h"
29 #include "wtf/PartitionAlloc.h" 29 #include "wtf/PartitionAlloc.h"
30 #include "wtf/Partitions.h" 30 #include "wtf/Partitions.h"
31 #include "wtf/PrintStream.h" 31 #include "wtf/PrintStream.h"
32 #include <algorithm> 32 #include <algorithm>
33 #include <string.h> 33 #include <string.h>
34 34
35 namespace WTF { 35 namespace WTF {
36 36
37 void BitVector::setSlow(const BitVector& other) 37 void BitVector::setSlow(const BitVector& other) {
38 { 38 uintptr_t newBitsOrPointer;
39 uintptr_t newBitsOrPointer; 39 if (other.isInline()) {
40 if (other.isInline()) { 40 newBitsOrPointer = other.m_bitsOrPointer;
41 newBitsOrPointer = other.m_bitsOrPointer; 41 } else {
42 } else { 42 OutOfLineBits* newOutOfLineBits = OutOfLineBits::create(other.size());
43 OutOfLineBits* newOutOfLineBits = OutOfLineBits::create(other.size()); 43 memcpy(newOutOfLineBits->bits(), other.bits(), byteCount(other.size()));
44 memcpy(newOutOfLineBits->bits(), other.bits(), byteCount(other.size())); 44 newBitsOrPointer = bitwise_cast<uintptr_t>(newOutOfLineBits) >> 1;
45 newBitsOrPointer = bitwise_cast<uintptr_t>(newOutOfLineBits) >> 1; 45 }
46 } 46 if (!isInline())
47 if (!isInline()) 47 OutOfLineBits::destroy(outOfLineBits());
48 OutOfLineBits::destroy(outOfLineBits()); 48 m_bitsOrPointer = newBitsOrPointer;
49 m_bitsOrPointer = newBitsOrPointer;
50 } 49 }
51 50
52 void BitVector::resize(size_t numBits) 51 void BitVector::resize(size_t numBits) {
53 { 52 if (numBits <= maxInlineBits()) {
54 if (numBits <= maxInlineBits()) { 53 if (isInline())
55 if (isInline()) 54 return;
56 return;
57 55
58 OutOfLineBits* myOutOfLineBits = outOfLineBits(); 56 OutOfLineBits* myOutOfLineBits = outOfLineBits();
59 m_bitsOrPointer = makeInlineBits(*myOutOfLineBits->bits()); 57 m_bitsOrPointer = makeInlineBits(*myOutOfLineBits->bits());
60 OutOfLineBits::destroy(myOutOfLineBits); 58 OutOfLineBits::destroy(myOutOfLineBits);
61 return; 59 return;
62 } 60 }
63 61
64 resizeOutOfLine(numBits); 62 resizeOutOfLine(numBits);
65 } 63 }
66 64
67 void BitVector::clearAll() 65 void BitVector::clearAll() {
68 { 66 if (isInline())
69 if (isInline()) 67 m_bitsOrPointer = makeInlineBits(0);
70 m_bitsOrPointer = makeInlineBits(0); 68 else
71 else 69 memset(outOfLineBits()->bits(), 0, byteCount(size()));
72 memset(outOfLineBits()->bits(), 0, byteCount(size()));
73 } 70 }
74 71
75 BitVector::OutOfLineBits* BitVector::OutOfLineBits::create(size_t numBits) 72 BitVector::OutOfLineBits* BitVector::OutOfLineBits::create(size_t numBits) {
76 { 73 // Because of the way BitVector stores the pointer, memory tools
77 // Because of the way BitVector stores the pointer, memory tools 74 // will erroneously report a leak here.
78 // will erroneously report a leak here. 75 WTF_INTERNAL_LEAK_SANITIZER_DISABLED_SCOPE;
79 WTF_INTERNAL_LEAK_SANITIZER_DISABLED_SCOPE; 76 numBits = (numBits + bitsInPointer() - 1) &
80 numBits = (numBits + bitsInPointer() - 1) & ~(bitsInPointer() - static_cast< size_t>(1)); 77 ~(bitsInPointer() - static_cast<size_t>(1));
81 size_t size = sizeof(OutOfLineBits) + sizeof(uintptr_t) * (numBits / bitsInP ointer()); 78 size_t size =
82 void* allocation = Partitions::bufferMalloc(size, WTF_HEAP_PROFILER_TYPE_NAM E(OutOfLineBits)); 79 sizeof(OutOfLineBits) + sizeof(uintptr_t) * (numBits / bitsInPointer());
83 OutOfLineBits* result = new (NotNull, allocation) OutOfLineBits(numBits); 80 void* allocation = Partitions::bufferMalloc(
84 return result; 81 size, WTF_HEAP_PROFILER_TYPE_NAME(OutOfLineBits));
82 OutOfLineBits* result = new (NotNull, allocation) OutOfLineBits(numBits);
83 return result;
85 } 84 }
86 85
87 void BitVector::OutOfLineBits::destroy(OutOfLineBits* outOfLineBits) 86 void BitVector::OutOfLineBits::destroy(OutOfLineBits* outOfLineBits) {
88 { 87 Partitions::bufferFree(outOfLineBits);
89 Partitions::bufferFree(outOfLineBits);
90 } 88 }
91 89
92 void BitVector::resizeOutOfLine(size_t numBits) 90 void BitVector::resizeOutOfLine(size_t numBits) {
93 { 91 ASSERT(numBits > maxInlineBits());
94 ASSERT(numBits > maxInlineBits()); 92 OutOfLineBits* newOutOfLineBits = OutOfLineBits::create(numBits);
95 OutOfLineBits* newOutOfLineBits = OutOfLineBits::create(numBits); 93 size_t newNumWords = newOutOfLineBits->numWords();
96 size_t newNumWords = newOutOfLineBits->numWords(); 94 if (isInline()) {
97 if (isInline()) { 95 // Make sure that all of the bits are zero in case we do a no-op resize.
98 // Make sure that all of the bits are zero in case we do a no-op resize. 96 *newOutOfLineBits->bits() =
99 *newOutOfLineBits->bits() = m_bitsOrPointer & ~(static_cast<uintptr_t>(1 ) << maxInlineBits()); 97 m_bitsOrPointer & ~(static_cast<uintptr_t>(1) << maxInlineBits());
100 memset(newOutOfLineBits->bits() + 1, 0, (newNumWords - 1) * sizeof(void* )); 98 memset(newOutOfLineBits->bits() + 1, 0, (newNumWords - 1) * sizeof(void*));
99 } else {
100 if (numBits > size()) {
101 size_t oldNumWords = outOfLineBits()->numWords();
102 memcpy(newOutOfLineBits->bits(), outOfLineBits()->bits(),
103 oldNumWords * sizeof(void*));
104 memset(newOutOfLineBits->bits() + oldNumWords, 0,
105 (newNumWords - oldNumWords) * sizeof(void*));
101 } else { 106 } else {
102 if (numBits > size()) { 107 memcpy(newOutOfLineBits->bits(), outOfLineBits()->bits(),
103 size_t oldNumWords = outOfLineBits()->numWords(); 108 newOutOfLineBits->numWords() * sizeof(void*));
104 memcpy(newOutOfLineBits->bits(), outOfLineBits()->bits(), oldNumWord s * sizeof(void*));
105 memset(newOutOfLineBits->bits() + oldNumWords, 0, (newNumWords - old NumWords) * sizeof(void*));
106 } else {
107 memcpy(newOutOfLineBits->bits(), outOfLineBits()->bits(), newOutOfLi neBits->numWords() * sizeof(void*));
108 }
109 OutOfLineBits::destroy(outOfLineBits());
110 } 109 }
111 m_bitsOrPointer = bitwise_cast<uintptr_t>(newOutOfLineBits) >> 1; 110 OutOfLineBits::destroy(outOfLineBits());
111 }
112 m_bitsOrPointer = bitwise_cast<uintptr_t>(newOutOfLineBits) >> 1;
112 } 113 }
113 114
114 void BitVector::dump(PrintStream& out) 115 void BitVector::dump(PrintStream& out) {
115 { 116 for (size_t i = 0; i < size(); ++i) {
116 for (size_t i = 0; i < size(); ++i) { 117 if (get(i))
117 if (get(i)) 118 out.printf("1");
118 out.printf("1"); 119 else
119 else 120 out.printf("-");
120 out.printf("-"); 121 }
121 }
122 } 122 }
123 123
124 } // namespace WTF 124 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/BitVector.h ('k') | third_party/WebKit/Source/wtf/BitwiseOperations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698