directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r159944 - directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/LocalPoolManager.java
Date Sun, 03 Apr 2005 17:56:39 GMT
Author: elecharny
Date: Sun Apr  3 10:56:39 2005
New Revision: 159944

URL: http://svn.apache.org/viewcvs?view=rev&rev=159944
Log:
Added the MutableString pools declarations, and a allocate method to select the right MutableString
pool's size 

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/LocalPoolManager.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/LocalPoolManager.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/LocalPoolManager.java?view=diff&r1=159943&r2=159944
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/LocalPoolManager.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/LocalPoolManager.java
Sun Apr  3 10:56:39 2005
@@ -94,6 +94,30 @@
 	
 	        pools[PoolEnum.LDAP_MESSAGE_POJO_POOL] = new LocalPool(
 	                PoolEnum.LDAP_MESSAGE_POJO_POOL, 1024, 1024 );
+
+	        pools[PoolEnum.STRING_POOL_16] = new LocalPool(
+	                PoolEnum.STRING_POOL_16, 10240, 10240 );
+
+	        pools[PoolEnum.STRING_POOL_32] = new LocalPool(
+	                PoolEnum.STRING_POOL_32, 10240, 10240 );
+	        
+	        pools[PoolEnum.STRING_POOL_64] = new LocalPool(
+	                PoolEnum.STRING_POOL_64, 10240, 10240 );
+	        
+	        pools[PoolEnum.STRING_POOL_128] = new LocalPool(
+	                PoolEnum.STRING_POOL_128, 5120, 5120 );
+	        
+	        pools[PoolEnum.STRING_POOL_256] = new LocalPool(
+	                PoolEnum.STRING_POOL_256, 1024, 1024 );
+	        
+	        pools[PoolEnum.STRING_POOL_512] = new LocalPool(
+	                PoolEnum.STRING_POOL_512, 512, 512 );
+
+	        pools[PoolEnum.STRING_POOL_1024] = new LocalPool(
+	                PoolEnum.STRING_POOL_1024, 256, 256 );
+
+	        pools[PoolEnum.STREAMED_STRING_POOL] = new LocalPool(
+	                PoolEnum.STREAMED_STRING_POOL, 256, 256 );
     	}
     }
 
@@ -115,6 +139,61 @@
     	else 
     	{
     		return PoolEnum.allocate(poolId);
+    	}
+    }
+
+    /**
+     * Allocate an string by asking its associated pool to deliver one.
+     *
+     * @param poolId The pool identifier. Each object has its own pool.
+     *
+     * @return An object newly created or available in the pool.
+     */
+    public PoolObject allocateString( int size ) throws PoolException
+    {
+    	if (isPooled)
+    	{
+    	    if (size > 1024)
+    	    {
+    	        return ( PoolObject ) pools[PoolEnum.STREAMED_STRING_POOL].allocate();
+    	    }
+    	    else
+    	    {
+    	        int poolId = ( ( size >> 4 ) + ( ( size & 0x0F ) != 0 ? 1 : 0) );
+    	        
+    	        switch (poolId)
+    	        {
+    	        	case 1 :
+    	        	    return ( PoolObject ) pools[PoolEnum.STRING_POOL_16].allocate();
+    	        	    
+    	        	case 2 :
+    	        	    return ( PoolObject ) pools[PoolEnum.STRING_POOL_32].allocate();
+
+    	        	case 4 :
+    	        	    return ( PoolObject ) pools[PoolEnum.STRING_POOL_64].allocate();
+
+    	        	case 8 :
+    	        	    return ( PoolObject ) pools[PoolEnum.STRING_POOL_128].allocate();
+
+    	        	case 16 :
+    	        	    return ( PoolObject ) pools[PoolEnum.STRING_POOL_256].allocate();
+
+    	        	case 32 :
+    	        	    return ( PoolObject ) pools[PoolEnum.STRING_POOL_512].allocate();
+
+    	        	case 64 :
+    	        	    return ( PoolObject ) pools[PoolEnum.STRING_POOL_1024].allocate();
+    	        	    
+    	        	default :
+    	        	    // We won't reach this default case, but we need it to
+    	        	    // avoid a compilation error !
+    	        	    return null;
+    	        }
+    	    }
+    	}
+    	else 
+    	{
+    		return ( PoolObject ) PoolEnum.allocate(size);
     	}
     }
 



Mime
View raw message