// { dg-do compile }
|
// { dg-do compile }
|
// { dg-require-effective-target fpic }
|
// { dg-require-effective-target fpic }
|
// { dg-require-visibility "" }
|
// { dg-require-visibility "" }
|
// { dg-options "-fPIC" }
|
// { dg-options "-fPIC" }
|
|
|
|
|
typedef __SIZE_TYPE__ size_t;
|
typedef __SIZE_TYPE__ size_t;
|
extern "C" void *
|
extern "C" void *
|
malloc (size_t __size)
|
malloc (size_t __size)
|
throw () __attribute__ ((__malloc__));
|
throw () __attribute__ ((__malloc__));
|
namespace std __attribute__ ((__visibility__ ("default")))
|
namespace std __attribute__ ((__visibility__ ("default")))
|
{
|
{
|
using::size_t;
|
using::size_t;
|
}
|
}
|
inline void *operator
|
inline void *operator
|
new (std::size_t, void *__p)
|
new (std::size_t, void *__p)
|
throw ()
|
throw ()
|
{
|
{
|
return __p;
|
return __p;
|
}
|
}
|
template < class _T1, class _T2 > struct pair
|
template < class _T1, class _T2 > struct pair
|
{
|
{
|
_T1 first;
|
_T1 first;
|
_T2 second;
|
_T2 second;
|
pair (const _T1 & __a, const _T2 & __b):first (__a), second (__b)
|
pair (const _T1 & __a, const _T2 & __b):first (__a), second (__b)
|
{
|
{
|
}
|
}
|
template < class _U1, class _U2 >
|
template < class _U1, class _U2 >
|
pair (const pair < _U1, _U2 > &__p):first (__p.first), second (__p.second)
|
pair (const pair < _U1, _U2 > &__p):first (__p.first), second (__p.second)
|
{
|
{
|
}
|
}
|
};
|
};
|
|
|
template < class _T1, class _T2 >
|
template < class _T1, class _T2 >
|
inline pair < _T1, _T2 > make_pair (_T1 __x, _T2 __y)
|
inline pair < _T1, _T2 > make_pair (_T1 __x, _T2 __y)
|
{
|
{
|
return pair < _T1, _T2 > (__x, __y);
|
return pair < _T1, _T2 > (__x, __y);
|
}
|
}
|
template < typename _Tp > inline const _Tp &
|
template < typename _Tp > inline const _Tp &
|
max (const _Tp & __a, const _Tp & __b)
|
max (const _Tp & __a, const _Tp & __b)
|
{
|
{
|
}
|
}
|
typedef unsigned short int uint16_t;
|
typedef unsigned short int uint16_t;
|
typedef unsigned long int uintptr_t;
|
typedef unsigned long int uintptr_t;
|
typedef uint16_t UChar;
|
typedef uint16_t UChar;
|
namespace std __attribute__ ((__visibility__ ("default")))
|
namespace std __attribute__ ((__visibility__ ("default")))
|
{
|
{
|
struct __numeric_limits_base
|
struct __numeric_limits_base
|
{
|
{
|
};
|
};
|
template < typename _Tp > struct numeric_limits:public __numeric_limits_base
|
template < typename _Tp > struct numeric_limits:public __numeric_limits_base
|
{
|
{
|
static _Tp max () throw ()
|
static _Tp max () throw ()
|
{
|
{
|
}
|
}
|
};
|
};
|
}
|
}
|
|
|
template < typename T > class VectorBufferBase
|
template < typename T > class VectorBufferBase
|
{
|
{
|
public:
|
public:
|
void allocateBuffer (size_t newCapacity)
|
void allocateBuffer (size_t newCapacity)
|
{
|
{
|
if (newCapacity > std::numeric_limits < size_t >::max () / sizeof (T))
|
if (newCapacity > std::numeric_limits < size_t >::max () / sizeof (T))
|
*(int *) (uintptr_t) 0xbbadbeef = 0;
|
*(int *) (uintptr_t) 0xbbadbeef = 0;
|
}
|
}
|
};
|
};
|
|
|
template < typename T, size_t inlineCapacity > class VectorBuffer;
|
template < typename T, size_t inlineCapacity > class VectorBuffer;
|
template < typename T > class VectorBuffer < T, 0 >:private VectorBufferBase <
|
template < typename T > class VectorBuffer < T, 0 >:private VectorBufferBase <
|
T >
|
T >
|
{
|
{
|
public:
|
public:
|
typedef VectorBufferBase < T > Base;
|
typedef VectorBufferBase < T > Base;
|
using Base::allocateBuffer;
|
using Base::allocateBuffer;
|
};
|
};
|
|
|
template < typename T, size_t inlineCapacity = 0 > class Vector
|
template < typename T, size_t inlineCapacity = 0 > class Vector
|
{
|
{
|
typedef VectorBuffer < T, inlineCapacity > Impl;
|
typedef VectorBuffer < T, inlineCapacity > Impl;
|
public:
|
public:
|
typedef T *iterator;
|
typedef T *iterator;
|
size_t size () const
|
size_t size () const
|
{
|
{
|
return m_size;
|
return m_size;
|
}
|
}
|
size_t capacity () const
|
size_t capacity () const
|
{
|
{
|
}
|
}
|
iterator begin ()
|
iterator begin ()
|
{
|
{
|
}
|
}
|
iterator end ()
|
iterator end ()
|
{
|
{
|
return begin () + m_size;
|
return begin () + m_size;
|
}
|
}
|
void shrink (size_t size);
|
void shrink (size_t size);
|
void reserveCapacity (size_t newCapacity);
|
void reserveCapacity (size_t newCapacity);
|
void clear ()
|
void clear ()
|
{
|
{
|
shrink (0);
|
shrink (0);
|
}
|
}
|
template < typename U > void append (const U &);
|
template < typename U > void append (const U &);
|
void expandCapacity (size_t newMinCapacity);
|
void expandCapacity (size_t newMinCapacity);
|
template < typename U > U * expandCapacity (size_t newMinCapacity, U *);
|
template < typename U > U * expandCapacity (size_t newMinCapacity, U *);
|
size_t m_size;
|
size_t m_size;
|
Impl m_impl;
|
Impl m_impl;
|
};
|
};
|
template < typename T, size_t inlineCapacity >
|
template < typename T, size_t inlineCapacity >
|
void Vector < T, inlineCapacity >::expandCapacity (size_t newMinCapacity)
|
void Vector < T, inlineCapacity >::expandCapacity (size_t newMinCapacity)
|
{
|
{
|
reserveCapacity (max
|
reserveCapacity (max
|
(newMinCapacity,
|
(newMinCapacity,
|
max (static_cast < size_t > (16),
|
max (static_cast < size_t > (16),
|
capacity () + capacity () / 4 + 1)));
|
capacity () + capacity () / 4 + 1)));
|
}
|
}
|
|
|
template < typename T, size_t inlineCapacity >
|
template < typename T, size_t inlineCapacity >
|
template < typename U >
|
template < typename U >
|
inline U * Vector < T,
|
inline U * Vector < T,
|
inlineCapacity >::expandCapacity (size_t newMinCapacity, U * ptr)
|
inlineCapacity >::expandCapacity (size_t newMinCapacity, U * ptr)
|
{
|
{
|
expandCapacity (newMinCapacity);
|
expandCapacity (newMinCapacity);
|
}
|
}
|
template < typename T, size_t inlineCapacity >
|
template < typename T, size_t inlineCapacity >
|
void Vector < T, inlineCapacity >::reserveCapacity (size_t newCapacity)
|
void Vector < T, inlineCapacity >::reserveCapacity (size_t newCapacity)
|
{
|
{
|
m_impl.allocateBuffer (newCapacity);
|
m_impl.allocateBuffer (newCapacity);
|
}
|
}
|
template < typename T, size_t inlineCapacity >
|
template < typename T, size_t inlineCapacity >
|
template < typename U >
|
template < typename U >
|
inline void Vector < T, inlineCapacity >::append (const U & val)
|
inline void Vector < T, inlineCapacity >::append (const U & val)
|
{
|
{
|
const U *ptr = &val;
|
const U *ptr = &val;
|
if (size () == capacity ())
|
if (size () == capacity ())
|
ptr = expandCapacity (size () + 1, ptr);
|
ptr = expandCapacity (size () + 1, ptr);
|
new (end ())T (*ptr);
|
new (end ())T (*ptr);
|
}
|
}
|
|
|
class Range;
|
class Range;
|
class TextIterator
|
class TextIterator
|
{
|
{
|
public:
|
public:
|
explicit TextIterator (const Range *,
|
explicit TextIterator (const Range *,
|
bool emitCharactersBetweenAllVisiblePositions =
|
bool emitCharactersBetweenAllVisiblePositions =
|
false);
|
false);
|
bool atEnd () const
|
bool atEnd () const
|
{
|
{
|
}
|
}
|
void advance ();
|
void advance ();
|
int length () const
|
int length () const
|
{
|
{
|
}
|
}
|
};
|
};
|
UChar *
|
UChar *
|
plainTextToMallocAllocatedBuffer (const Range * r, unsigned &bufferLength)
|
plainTextToMallocAllocatedBuffer (const Range * r, unsigned &bufferLength)
|
{
|
{
|
static const unsigned cMaxSegmentSize = 1 << 16;
|
static const unsigned cMaxSegmentSize = 1 << 16;
|
typedef pair < UChar *, unsigned >TextSegment;
|
typedef pair < UChar *, unsigned >TextSegment;
|
Vector < TextSegment > *textSegments = 0;
|
Vector < TextSegment > *textSegments = 0;
|
Vector < UChar > textBuffer;
|
Vector < UChar > textBuffer;
|
for (TextIterator it (r); !it.atEnd (); it.advance ())
|
for (TextIterator it (r); !it.atEnd (); it.advance ())
|
{
|
{
|
if (textBuffer.size ()
|
if (textBuffer.size ()
|
&& textBuffer.size () + it.length () > cMaxSegmentSize)
|
&& textBuffer.size () + it.length () > cMaxSegmentSize)
|
{
|
{
|
UChar *newSegmentBuffer =
|
UChar *newSegmentBuffer =
|
static_cast <
|
static_cast <
|
UChar * >(malloc (textBuffer.size () * sizeof (UChar)));
|
UChar * >(malloc (textBuffer.size () * sizeof (UChar)));
|
if (!textSegments)
|
if (!textSegments)
|
textSegments = new Vector < TextSegment >;
|
textSegments = new Vector < TextSegment >;
|
textSegments->
|
textSegments->
|
append (make_pair (newSegmentBuffer, textBuffer.size ()));
|
append (make_pair (newSegmentBuffer, textBuffer.size ()));
|
textBuffer.clear ();
|
textBuffer.clear ();
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|