| 80 | } |
| 81 | |
| 82 | ConstObjectPtr ObjectPool::store( const Object *obj, StoreMode mode ) |
| 83 | { |
| 84 | MurmurHash h = obj->hash(); |
| 85 | |
| 86 | // first tries to see if the object is already in the cache and return that one quickly. |
| 87 | ConstObjectPtr cachedObj = m_data->cache.get(h); |
| 88 | if ( cachedObj ) |
| 89 | { |
| 90 | return cachedObj; |
| 91 | } |
| 92 | |
| 93 | if ( mode == StoreCopy ) |
| 94 | { |
| 95 | cachedObj = obj->copy(); |
| 96 | m_data->cache.set( h, cachedObj, obj->memoryUsage() ); |
| 97 | return cachedObj; |
| 98 | } |
| 99 | else if ( mode == StoreReference ) |
| 100 | { |
| 101 | m_data->cache.set( h, obj, obj->memoryUsage() ); |
| 102 | return obj; |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | throw Exception( "Invalid store mode!" ); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | bool ObjectPool::contains( const MurmurHash &hash ) const |
| 111 | { |