Module: Moxml::Adapter::Leptris::Identity::Reads

Defined in:
lib/moxml/adapter/leptris.rb,
lib/moxml/adapter/leptris.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



250
251
252
253
254
255
256
257
258
259
# File 'lib/moxml/adapter/leptris.rb', line 250

def [](key)
  if key.is_a?(String) && !key.include?(":")
    value = attr_read(key)
    return value unless value.is_a?(String) && doc_entity_bearing?

    return ::Moxml::Adapter::Leptris.restore_entities(value)
  end

  ELEMENT_CONTRACT_READ.bind_call(self, key)
end

#doc_entity_bearing?Boolean

Marker presence is a DOCUMENT fact, but the wrapper memo re-derives it per node (the per-read machinery was ~a quarter of the consumer walk). Doc-level WeakMap, generation-stamped into one Integer (immediates make safe weak values): one C document read plus one map hit per bare read. Entries die with their documents; a stale generation re-derives.

Returns:



239
240
241
242
243
244
245
246
247
248
# File 'lib/moxml/adapter/leptris.rb', line 239

def doc_entity_bearing?
  doc = NN_DOCUMENT.bind_call(self)
  memo = ENTITY_DOC_MEMO[doc]
  gen = ::Moxml::Adapter::Leptris.serialize_generation
  return memo.allbits?(1) if memo && (memo >> 1) == gen

  bearing = ::Moxml::Adapter::Leptris.entity_bearing?(self)
  ENTITY_DOC_MEMO[doc] = (gen << 1) | (bearing ? 1 : 0)
  bearing
end

#textObject



261
262
263
264
# File 'lib/moxml/adapter/leptris.rb', line 261

def text
  value = text_read
  value.is_a?(String) && doc_entity_bearing? ? ::Moxml::Adapter::Leptris.restore_entities(value) : value
end