hphp/runtime/base/string-data.cpp
// create either a static or an uncounted string.
// Diffrence between static and uncounted is in the lifetime
// of the string. Static are alive for the lifetime of the process.
// Uncounted are not ref counted but will be deleted at some point.
create either a static or an uncounted string.
Diffrence between static and uncounted is in the lifetime
of the string. Static are alive for the lifetime of the process.
Uncounted are not ref counted but will be deleted at some point.
create either a static or an uncounted string . Diffrence between static and uncounted is in the lifetime of the string . Static are alive for the lifetime of the process . Uncounted are not ref counted but will be deleted at some point .
StringData* StringData::MakeShared(StringSlice sl, bool trueStatic) {
  if (UNLIKELY(sl.len > StringData::MaxSize)) {
    throw_string_too_large(sl.len);
  }
  auto const sd = static_cast<StringData*>(
    Util::low_malloc(sizeof(StringData) + sl.len + 1)
  );
  auto const data = reinterpret_cast<char*>(sd + 1);
  sd->m_data        = data;
  sd->m_lenAndCount = sl.len;
  sd->m_capAndHash  = sl.len + 1;
  data[sl.len] = 0;
  auto const mcret = memcpy(data, sl.ptr, sl.len);
  auto const ret   = reinterpret_cast<StringData*>(mcret) - 1;
  assert(ret->m_hash == 0);
  assert(ret->m_count == 0);
  if (trueStatic) {
    ret->setStatic();
  } else {
    ret->setUncounted();
  }
  assert(ret == sd);
  assert(ret->isFlat());
  assert(trueStatic ? ret->isStatic() : ret->isUncounted());
  assert(ret->checkSane());
  return ret;
}
StringData * StringData :: MakeShared ( StringSlice sl , bool trueStatic ) { if ( UNLIKELY ( sl . len > StringData :: MaxSize ) ) { throw_string_too_large ( sl . len ) ; } auto const sd = static_cast < StringData * > ( Util :: low_malloc ( sizeof ( StringData ) + sl . len + 1 ) ) ; auto const data = reinterpret_cast < char * > ( sd + 1 ) ; sd -> m_data = data ; sd -> m_lenAndCount = sl . len ; sd -> m_capAndHash = sl . len + 1 ; data [ sl . len ] = 0 ; auto const mcret = memcpy ( data , sl . ptr , sl . len ) ; auto const ret = reinterpret_cast < StringData * > ( mcret ) - 1 ; assert ( ret -> m_hash == 0 ) ; assert ( ret -> m_count == 0 ) ; if ( trueStatic ) { ret -> setStatic ( ) ; } else { ret -> setUncounted ( ) ; } assert ( ret == sd ) ; assert ( ret -> isFlat ( ) ) ; assert ( trueStatic ? ret -> isStatic ( ) : ret -> isUncounted ( ) ) ; assert ( ret -> checkSane ( ) ) ; return ret ; }
create either a static or an uncounted string.
create either a static or an uncounted string .
// Recalculating ret from mcret avoids a spill.