{
template<typename Stringpool_char>
-Stringpool_template<Stringpool_char>::Stringpool_template()
+Stringpool_template<Stringpool_char>::Stringpool_template(uint64_t addralign)
: string_set_(), key_to_offset_(), strings_(), strtab_size_(0),
- zero_null_(true), optimize_(false), offset_(0)
+ zero_null_(true), optimize_(false), offset_(sizeof(Stringpool_char)),
+ addralign_(addralign)
{
if (parameters->options_valid() && parameters->options().optimize() >= 2)
this->optimize_ = true;
this->string_set_.swap(new_string_set);
}
-// Return the length of a string of arbitrary character type.
-
-template<typename Stringpool_char>
-size_t
-Stringpool_template<Stringpool_char>::string_length(const Stringpool_char* p)
-{
- size_t len = 0;
- for (; *p != 0; ++p)
- ++len;
- return len;
-}
-
-// Specialize string_length for char. Maybe we could just use
-// std::char_traits<>::length?
-
-template<>
-inline size_t
-Stringpool_template<char>::string_length(const char* p)
-{
- return strlen(p);
-}
-
// Compare two strings of arbitrary character type for equality.
template<typename Stringpool_char>
alc = sizeof(Stringdata) + buffer_size;
else
{
- Stringdata *psd = this->strings_.front();
+ Stringdata* psd = this->strings_.front();
if (len > psd->alc - psd->len)
alc = sizeof(Stringdata) + buffer_size;
else
}
}
- Stringdata *psd = reinterpret_cast<Stringdata*>(new char[alc]);
+ Stringdata* psd = reinterpret_cast<Stringdata*>(new char[alc]);
psd->alc = alc - sizeof(Stringdata);
memcpy(psd->data, s, len - sizeof(Stringpool_char));
memset(psd->data + len - sizeof(Stringpool_char), 0,
void
Stringpool_template<Stringpool_char>::new_key_offset(size_t length)
{
- if (this->key_to_offset_.size() == 0)
- this->offset_ = this->zero_null_ ? sizeof(Stringpool_char) : 0;
-
section_offset_type offset;
if (this->zero_null_ && length == 0)
offset = 0;
else
{
offset = this->offset_;
- this->offset_ += (length + 1) * sizeof(Stringpool_char);
+ // Align non-zero length strings.
+ if (length != 0)
+ offset = align_address(offset, this->addralign_);
+ this->offset_ = offset + (length + 1) * sizeof(Stringpool_char);
}
this->key_to_offset_.push_back(offset);
}
* charsize));
else
{
- this_offset = offset;
- offset += ((*curr)->first.length + 1) * charsize;
+ this_offset = align_address(offset, this->addralign_);
+ offset = this_offset + ((*curr)->first.length + 1) * charsize;
}
this->key_to_offset_[(*curr)->second - 1] = this_offset;
last_offset = this_offset;