Exemplo n.º 1
0
 void LookupCacheBuilder::cleanup()
 {
     if (caches) {
         mmfx_delete_array(caches);
         caches = NULL;
     }
 }
Exemplo n.º 2
0
	bool ByteArray::Grow(uint32_t minimumCapacity)
	{
		if (minimumCapacity > m_capacity)
		{
			uint32_t newCapacity = m_capacity << 1;			
			if (newCapacity < minimumCapacity)
			{
				newCapacity = minimumCapacity;
			}
			if (newCapacity < kGrowthIncr) 
			{
				newCapacity = kGrowthIncr;
			}
			U8 *newArray = mmfx_new_array(uint8_t, newCapacity);
			if (!newArray)
			{
				return false;
			}
			if (m_array)
			{
				VMPI_memcpy(newArray, m_array, m_length);
				mmfx_delete_array(m_array);
			}
			VMPI_memset(newArray+m_length, 0, newCapacity-m_capacity);
			m_array = newArray;
			m_capacity = newCapacity;
			NotifySubscribers();
		}
		return true;
	}
Exemplo n.º 3
0
	String* DataInput::ReadUTFBytes(uint32_t length)
	{
		CheckEOF(length);
		
		char *buffer = mmfx_new_array_opt( char, length+1, MMgc::kCanFail );
		if (!buffer) {
			ThrowMemoryError();
		}

		Read(buffer, length);
		buffer[length] = 0;
		
		// Since this is supposed to read UTF8 into a string, it really should ignore the UTF8 BOM that
		// might reasonably occur at the head of the data.
		char* utf8chars = buffer;
		if (length >= 3 && (unsigned char)buffer[0] == 0xEF && (unsigned char)buffer[1] == 0xBB && (unsigned char)buffer[2] == 0xBF) 
		{
			utf8chars += 3;
		}

		String *out = m_toplevel->core()->newStringUTF8(utf8chars);
		mmfx_delete_array( buffer );
		
		return out;
	}
Exemplo n.º 4
0
	ByteArray::~ByteArray()
	{
		m_subscriberRoot = NULL;
		if (m_array)
		{
			mmfx_delete_array(m_array);
			m_array = NULL;
		}
		m_capacity = 0;
		m_length = 0;
	}
Exemplo n.º 5
0
 // The cache structure is expected to be small in the normal case, so use a
 // linear list.  For some programs, notably classical JS programs, it may however
 // be larger, and we may need a more sophisticated structure.
 uint32_t LookupCacheBuilder::allocateCacheSlot(uint32_t imm30)
 {
     for ( int i=0 ; i < next_cache ; i++ )
         if (caches[i] == imm30)
             return i;
     if (next_cache == num_caches) {
         uint32_t newcap = num_caches + num_caches/2 + 5; // 0 5 12 23 39 66 ...
         uint32_t* new_cache = mmfx_new_array(uint32_t, newcap);
         if (num_caches > 0) {
             VMPI_memcpy(new_cache, caches, sizeof(uint32_t)*num_caches);
             mmfx_delete_array(caches);
         }
         caches = new_cache;
         num_caches = newcap;
     }
     caches[next_cache] = imm30;
     return next_cache++;
 }