调整锁位置和 不必要的int拆箱

This commit is contained in:
handy 2023-05-09 13:48:56 +08:00
parent 2fd1d5db70
commit 9dadfed42e
3 changed files with 6 additions and 9 deletions

View File

@ -144,8 +144,8 @@ public abstract class ReentrantCache<K, V> extends AbstractCache<K, V> {
* @param withMissCount 是否计数丢失数 * @param withMissCount 是否计数丢失数
*/ */
private void remove(final K key, final boolean withMissCount) { private void remove(final K key, final boolean withMissCount) {
lock.lock();
CacheObj<K, V> co; CacheObj<K, V> co;
lock.lock();
try { try {
co = removeWithoutLock(key, withMissCount); co = removeWithoutLock(key, withMissCount);
} finally { } finally {

View File

@ -365,7 +365,7 @@ public class Ipv4Util implements Ipv4Pool {
* @return 掩码位例如 24 * @return 掩码位例如 24
* @throws IllegalArgumentException 子网掩码非法 * @throws IllegalArgumentException 子网掩码非法
*/ */
public static int getMaskBitByMask(final String mask) { public static Integer getMaskBitByMask(final String mask) {
final Integer maskBit = MaskBit.getMaskBit(mask); final Integer maskBit = MaskBit.getMaskBit(mask);
Assert.notNull(maskBit, "Invalid netmask{}", mask); Assert.notNull(maskBit, "Invalid netmask{}", mask);
return maskBit; return maskBit;

View File

@ -302,9 +302,8 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
* @since 6.0.0 * @since 6.0.0
*/ */
public byte[] encrypt(final byte[] data, final byte[] salt) { public byte[] encrypt(final byte[] data, final byte[] salt) {
lock.lock();
byte[] result; byte[] result;
lock.lock();
try { try {
final Cipher cipher = initMode(Cipher.ENCRYPT_MODE, salt); final Cipher cipher = initMode(Cipher.ENCRYPT_MODE, salt);
result = cipher.doFinal(paddingDataWithZero(data, cipher.getBlockSize())); result = cipher.doFinal(paddingDataWithZero(data, cipher.getBlockSize()));
@ -318,9 +317,8 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
@Override @Override
public void encrypt(final InputStream data, final OutputStream out, final boolean isClose) throws IORuntimeException { public void encrypt(final InputStream data, final OutputStream out, final boolean isClose) throws IORuntimeException {
lock.lock();
CipherOutputStream cipherOutputStream = null; CipherOutputStream cipherOutputStream = null;
lock.lock();
try { try {
final Cipher cipher = initMode(Cipher.ENCRYPT_MODE, null); final Cipher cipher = initMode(Cipher.ENCRYPT_MODE, null);
cipherOutputStream = new CipherOutputStream(out, cipher); cipherOutputStream = new CipherOutputStream(out, cipher);
@ -358,10 +356,9 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
public byte[] decrypt(final byte[] bytes) { public byte[] decrypt(final byte[] bytes) {
final int blockSize; final int blockSize;
final byte[] decryptData; final byte[] decryptData;
lock.lock(); lock.lock();
final byte[] salt = SaltMagic.getSalt(bytes);
try { try {
final byte[] salt = SaltMagic.getSalt(bytes);
final Cipher cipher = initMode(Cipher.DECRYPT_MODE, salt); final Cipher cipher = initMode(Cipher.DECRYPT_MODE, salt);
blockSize = cipher.getBlockSize(); blockSize = cipher.getBlockSize();
decryptData = cipher.doFinal(SaltMagic.getData(bytes)); decryptData = cipher.doFinal(SaltMagic.getData(bytes));
@ -376,8 +373,8 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
@Override @Override
public void decrypt(final InputStream data, final OutputStream out, final boolean isClose) throws IORuntimeException { public void decrypt(final InputStream data, final OutputStream out, final boolean isClose) throws IORuntimeException {
lock.lock();
CipherInputStream cipherInputStream = null; CipherInputStream cipherInputStream = null;
lock.lock();
try { try {
final Cipher cipher = initMode(Cipher.DECRYPT_MODE, null); final Cipher cipher = initMode(Cipher.DECRYPT_MODE, null);
cipherInputStream = new CipherInputStream(data, cipher); cipherInputStream = new CipherInputStream(data, cipher);