Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 8a244ad

Browse files
author
Sergey Andreenko
committed
Move iterator inside BitSetOps.
It is in for bitsetasuint and bitsetshortlong, but what out for bitsetasuint64inclass. And there is no need to be friends for them.
1 parent 67003c4 commit 8a244ad

File tree

2 files changed

+46
-52
lines changed

2 files changed

+46
-52
lines changed

src/jit/bitsetasshortlong.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,6 @@ class BitSetOps</*BitSetType*/ BitSetShortLongRep,
540540
}
541541
};
542542

543-
friend class Iter;
544-
545543
typedef const BitSetShortLongRep& ValArgType;
546544
typedef BitSetShortLongRep RetValType;
547545
};

src/jit/bitsetasuint64inclass.h

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class BitSetUint64
2828
/*BitSetTraits*/ BitSetTraits>;
2929

3030
friend class BitSetUint64ValueRetType<Env, BitSetTraits>;
31-
friend class BitSetUint64Iter<Env, BitSetTraits>;
3231

3332
UINT64 m_bits;
3433

@@ -282,54 +281,6 @@ BitSetUint64<Env, BitSetTraits>::BitSetUint64(const BitSetUint64ValueRetType<Env
282281
{
283282
}
284283

285-
// You *can* clear a bit after it's been iterated. But you shouldn't otherwise mutate the
286-
// bitset during bit iteration.
287-
template <typename Env, typename BitSetTraits>
288-
class BitSetUint64Iter
289-
{
290-
UINT64 m_bits;
291-
unsigned m_bitNum;
292-
293-
public:
294-
BitSetUint64Iter(Env env, const BitSetUint64<Env, BitSetTraits>& bs) : m_bits(bs.m_bits), m_bitNum(0)
295-
{
296-
}
297-
298-
int NextElem()
299-
{
300-
static const unsigned UINT64_SIZE = 64;
301-
302-
if ((m_bits & 0x1) != 0)
303-
{
304-
m_bits >>= 1;
305-
return m_bitNum++;
306-
}
307-
else
308-
{
309-
// Skip groups of 4 zeros -- an optimization for sparse bitsets.
310-
while (m_bitNum < UINT64_SIZE && (m_bits & 0xf) == 0)
311-
{
312-
m_bitNum += 4;
313-
m_bits >>= 4;
314-
}
315-
while (m_bitNum < UINT64_SIZE && (m_bits & 0x1) == 0)
316-
{
317-
m_bitNum += 1;
318-
m_bits >>= 1;
319-
}
320-
if (m_bitNum < UINT64_SIZE)
321-
{
322-
m_bits >>= 1;
323-
return m_bitNum++;
324-
}
325-
else
326-
{
327-
return -1;
328-
}
329-
}
330-
}
331-
};
332-
333284
template <typename Env, typename BitSetTraits>
334285
class BitSetOps</*BitSetType*/ BitSetUint64<Env, BitSetTraits>,
335286
/*Brand*/ BSUInt64Class,
@@ -508,7 +459,52 @@ class BitSetOps</*BitSetType*/ BitSetUint64<Env, BitSetTraits>,
508459
}
509460
#endif
510461

511-
typedef BitSetUint64Iter<Env, BitSetTraits> Iter;
462+
// You *can* clear a bit after it's been iterated. But you shouldn't otherwise mutate the
463+
// bitset during bit iteration.
464+
class Iter
465+
{
466+
UINT64 m_bits;
467+
unsigned m_bitNum;
468+
469+
public:
470+
Iter(Env env, const BitSetUint64<Env, BitSetTraits>& bs) : m_bits(bs.m_bits), m_bitNum(0)
471+
{
472+
}
473+
474+
int NextElem()
475+
{
476+
static const unsigned UINT64_SIZE = 64;
477+
478+
if ((m_bits & 0x1) != 0)
479+
{
480+
m_bits >>= 1;
481+
return m_bitNum++;
482+
}
483+
else
484+
{
485+
// Skip groups of 4 zeros -- an optimization for sparse bitsets.
486+
while (m_bitNum < UINT64_SIZE && (m_bits & 0xf) == 0)
487+
{
488+
m_bitNum += 4;
489+
m_bits >>= 4;
490+
}
491+
while (m_bitNum < UINT64_SIZE && (m_bits & 0x1) == 0)
492+
{
493+
m_bitNum += 1;
494+
m_bits >>= 1;
495+
}
496+
if (m_bitNum < UINT64_SIZE)
497+
{
498+
m_bits >>= 1;
499+
return m_bitNum++;
500+
}
501+
else
502+
{
503+
return -1;
504+
}
505+
}
506+
}
507+
};
512508

513509
typedef const BitSetUint64<Env, BitSetTraits>& ValArgType;
514510
typedef BitSetUint64ValueRetType<Env, BitSetTraits> RetValType;

0 commit comments

Comments
 (0)