SkBitSet: cleanup. Remove unused fn, more general exporter.

Change-Id: I090a20decf30631f2464a820c6a056a81b6cc1a3
Reviewed-on: https://skia-review.googlesource.com/c/163784
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Hal Canary 2018-10-19 10:08:42 -04:00 committed by Skia Commit-Bot
parent 1f7e4385d2
commit 52514d5f67
5 changed files with 21 additions and 27 deletions

View File

@ -358,7 +358,7 @@ static sk_sp<SkPDFStream> get_subset_font_stream(
if (!glyphUsage.has(0)) {
subset.push_back(0); // Always include glyph 0.
}
glyphUsage.exportTo(&subset);
glyphUsage.getSetValues([&subset](unsigned v) { subset.push_back(v); });
unsigned char* subsetFont{nullptr};
sk_sp<SkData> fontData(stream_to_data(std::move(fontAsset)));

View File

@ -10,8 +10,6 @@
#include "SkTemplates.h"
#include <vector>
class SkBitSet {
public:
explicit SkBitSet(int numberOfBits) {
@ -30,33 +28,22 @@ public:
*chunk |= mask;
}
template<typename T>
void setAll(T* array, int len) {
static_assert(std::is_integral<T>::value, "T is integral");
for (int i = 0; i < len; ++i) {
this->set(static_cast<int>(array[i]));
}
}
bool has(int index) const {
const uint32_t* chunk = this->internalGet(index);
uint32_t mask = 1 << (index & 31);
return chunk && SkToBool(*chunk & mask);
}
/** Export indices of set bits to T array. */
template<typename T>
void exportTo(std::vector<T>* array) const {
static_assert(std::is_integral<T>::value, "T is integral");
SkASSERT(array);
uint32_t* data = reinterpret_cast<uint32_t*>(fBitData.get());
for (unsigned int i = 0; i < fDwordCount; ++i) {
uint32_t value = data[i];
if (value) { // There are set bits
unsigned int index = i * 32;
for (unsigned int j = 0; j < 32; ++j) {
// Calls f(unsigned) for each set value.
template<typename FN>
void getSetValues(FN f) const {
const uint32_t* data = fBitData.get();
for (unsigned i = 0; i < fDwordCount; ++i) {
if (uint32_t value = data[i]) { // There are set bits
unsigned index = i * 32;
for (unsigned j = 0; j < 32; ++j) {
if (0x1 & (value >> j)) {
array->push_back(index + j);
f(index | j);
}
}
}

View File

@ -333,7 +333,9 @@ static HRESULT subset_typeface(SkXPSDevice::TypefaceUse* current) {
//CreateFontPackage wants unsigned short.
//Microsoft, Y U NO stdint.h?
std::vector<unsigned short> keepList;
current->glyphsUsed->exportTo(&keepList);
current->glyphsUsed->getSetValues([&keepList](unsigned v) {
keepList.push_back((unsigned short)v);
});
int ttcCount = (current->ttcIndex + 1);

View File

@ -26,7 +26,8 @@ DEF_TEST(BitSet, reporter) {
REPORTER_ASSERT(reporter, set0.has(35) == true);
std::vector<unsigned int> data;
set0.exportTo(&data);
set0.getSetValues([&data](unsigned v) { data.push_back(v); });
REPORTER_ASSERT(reporter, data.size() == 3);
REPORTER_ASSERT(reporter, data[0] == 22);
REPORTER_ASSERT(reporter, data[1] == 24);

View File

@ -78,7 +78,9 @@ DEF_TEST(SkPDF_ToUnicode, reporter) {
SkGlyphID lastGlyphID = SkToU16(glyphToUnicode.count() - 1);
SkDynamicMemoryWStream buffer;
subset.setAll(glyphsInSubset.begin(), glyphsInSubset.count());
for (uint16_t v : glyphsInSubset) {
subset.set(v);
}
SkPDFAppendCmapSections(&glyphToUnicode[0], &subset, &buffer, true, 0,
SkTMin<SkGlyphID>(0xFFFF, lastGlyphID));
@ -172,7 +174,9 @@ endbfrange\n";
glyphsInSubset.push_back(0x57);
SkDynamicMemoryWStream buffer2;
subset2.setAll(glyphsInSubset.begin(), glyphsInSubset.count());
for (uint16_t v : glyphsInSubset) {
subset2.set(v);
}
SkPDFAppendCmapSections(&glyphToUnicode[0], &subset2, &buffer2, true, 0,
SkTMin<SkGlyphID>(0xFFFF, lastGlyphID));