From: Mailing l. f. S. c. m. <jtc...@li...> - 2011-03-13 10:47:26
|
Revision: 3307 http://jtcfrost.svn.sourceforge.net/jtcfrost/?rev=3307&view=rev Author: artur8ur Date: 2011-03-13 10:47:19 +0000 (Sun, 13 Mar 2011) Log Message: ----------- Removed old code and removed some unnecessary method calls from inside of loops. Modified Paths: -------------- trunk/frost-wot/source/frost/storage/perst/filelist/FileListStorage.java trunk/frost-wot/source/frost/storage/perst/identities/IdentitiesStorage.java trunk/frost-wot/source/frost/storage/perst/messages/MessageStorage.java Modified: trunk/frost-wot/source/frost/storage/perst/filelist/FileListStorage.java =================================================================== --- trunk/frost-wot/source/frost/storage/perst/filelist/FileListStorage.java 2011-03-13 09:58:05 UTC (rev 3306) +++ trunk/frost-wot/source/frost/storage/perst/filelist/FileListStorage.java 2011-03-13 10:47:19 UTC (rev 3307) @@ -224,9 +224,10 @@ public void resetHiddenFiles() { if( beginExclusiveThreadTransaction() ) { try { + final Storage storage = getStorage(); for (final Iterator<PerstHiddenFileOid> it = storageRoot.getHiddenFileOids().iterator(); it.hasNext(); ) { final PerstHiddenFileOid hf = it.next(); - final FrostFileListFileObject fof = (FrostFileListFileObject) getStorage().getObjectByOID(hf.getHiddenFileOid()); + final FrostFileListFileObject fof = (FrostFileListFileObject) storage.getObjectByOID(hf.getHiddenFileOid()); if (fof != null && fof.isHidden()) { fof.setHidden(false); fof.modify(); @@ -274,15 +275,6 @@ return 0; } -// final boolean removeOld07ChkKeys; -// if( FcpHandler.isFreenet07() -// && (storageRoot.getStorageStatus() & FileListStorageRoot.OLD_07_CHK_KEYS_REMOVED) == 0 ) -// { -// removeOld07ChkKeys = true; -// } else { -// removeOld07ChkKeys = false; -// } - int count = 0; try { final long minVal = System.currentTimeMillis() - (offlineFilesMaxDaysOld * 24L * 60L * 60L * 1000L); @@ -302,11 +294,6 @@ // has no key remove = true; } - -// } else if( removeOld07ChkKeys && FreenetKeys.isOld07ChkKey(o.getKey()) ) { -// // we have a key (outdated or not) -// // check if the key is an old 0.7 CHK key -// remove = true; } if( remove ) { @@ -352,15 +339,6 @@ return 0; } -// final boolean removeOld07ChkKeys; -// if( FcpHandler.isFreenet07() -// && (storageRoot.getStorageStatus() & FileListStorageRoot.OLD_07_CHK_KEYS_REMOVED) == 0 ) -// { -// removeOld07ChkKeys = true; -// } else { -// removeOld07ChkKeys = false; -// } - int count = 0; try { final HashSet<Integer> oidsToRemove = new HashSet<Integer>(); @@ -386,13 +364,6 @@ endThreadTransaction(); } -// if( removeOld07ChkKeys ) { -// // we removed the keys, update flag -// final int newStorageStatus = storageRoot.getStorageStatus() | FileListStorageRoot.OLD_07_CHK_KEYS_REMOVED; -// storageRoot.setStorageStatus( newStorageStatus ); -// storageRoot.modify(); -// } - return count; } @@ -581,11 +552,13 @@ { for(final Map.Entry<Object,PerstFileListIndexEntry> entry : ix.entryIterator() ) { final String key = (String)entry.getKey(); + IPersistentList<FrostFileListFileObjectOwner> fileOwnersWithText = entry.getValue().getFileOwnersWithText(); + if( searchStrings != null ) { for(final String searchString : searchStrings) { if( key.indexOf(searchString) > -1 ) { // add all owner oids - final Iterator<FrostFileListFileObjectOwner> i = entry.getValue().getFileOwnersWithText().iterator(); + final Iterator<FrostFileListFileObjectOwner> i = fileOwnersWithText.iterator(); while(i.hasNext()) { final int oid = ((PersistentIterator)i).nextOid(); oids.add(oid); @@ -593,11 +566,12 @@ } } } + if( extensions != null ) { for( final String extension : extensions ) { if( key.endsWith(extension) ) { // add all owner oids - final Iterator<FrostFileListFileObjectOwner> i = entry.getValue().getFileOwnersWithText().iterator(); + final Iterator<FrostFileListFileObjectOwner> i = fileOwnersWithText.iterator(); while(i.hasNext()) { final int oid = ((PersistentIterator)i).nextOid(); oids.add(oid); @@ -623,13 +597,6 @@ && !oldFof.getKey().equals(newFof.getKey()) ) { oldFof.setKey(newFof.getKey()); doUpdate = true; - -// } else if( oldFof.getKey() != null && newFof.getKey() != null ) { -// // fix to replace 0.7 keys before 1010 on the fly -// if( FreenetKeys.isOld07ChkKey(oldFof.getKey()) ) { -// // replace old chk key with new one -// oldFof.setKey(newFof.getKey()); doUpdate = true; -// } } if( oldFof.getFirstReceived() > newFof.getFirstReceived() ) { oldFof.setFirstReceived(newFof.getFirstReceived()); doUpdate = true; @@ -656,13 +623,13 @@ oldFof.setRequestsSentCount(newFof.getRequestsSentCount()); doUpdate = true; } - for(final Iterator<FrostFileListFileObjectOwner> i=newFof.getFrostFileListFileObjectOwnerIterator(); i.hasNext(); ) { + for(final Iterator<FrostFileListFileObjectOwner> i = newFof.getFrostFileListFileObjectOwnerIterator(); i.hasNext(); ) { final FrostFileListFileObjectOwner obNew = i.next(); // check if we have an owner object for this sharer FrostFileListFileObjectOwner obOld = null; - for(final Iterator<FrostFileListFileObjectOwner> j=oldFof.getFrostFileListFileObjectOwnerIterator(); j.hasNext(); ) { + for(final Iterator<FrostFileListFileObjectOwner> j = oldFof.getFrostFileListFileObjectOwnerIterator(); j.hasNext(); ) { final FrostFileListFileObjectOwner o = j.next(); if( o.getOwner().equals(obNew.getOwner()) ) { obOld = o; Modified: trunk/frost-wot/source/frost/storage/perst/identities/IdentitiesStorage.java =================================================================== --- trunk/frost-wot/source/frost/storage/perst/identities/IdentitiesStorage.java 2011-03-13 09:58:05 UTC (rev 3306) +++ trunk/frost-wot/source/frost/storage/perst/identities/IdentitiesStorage.java 2011-03-13 10:47:19 UTC (rev 3307) @@ -21,6 +21,8 @@ import java.util.*; import java.util.logging.*; +import org.garret.perst.IPersistentList; + import frost.*; import frost.identities.*; import frost.storage.*; @@ -241,30 +243,20 @@ final Hashtable<String,IdentityMsgAndFileCount> data = new Hashtable<String,IdentityMsgAndFileCount>(); -// for(final Iterator<Identity> i = storageRoot.getIdentities().iterator(); i.hasNext(); ) { -// final Identity id = i.next(); -// if( id == null ) { -// i.remove(); -// continue; -// } for( final Identity id : Core.getIdentities().getIdentities() ) { - final int messageCount = MessageStorage.inst().getMessageCount(id.getUniqueName()); - final int fileCount = FileListStorage.inst().getFileCount(id.getUniqueName()); - final IdentityMsgAndFileCount s = new IdentityMsgAndFileCount(messageCount, fileCount); - data.put(id.getUniqueName(), s); + final String uniqueName = id.getUniqueName(); + final int messageCount = MessageStorage.inst().getMessageCount(uniqueName); + final int fileCount = FileListStorage.inst().getFileCount(uniqueName); + final IdentityMsgAndFileCount identityMsgAndFileCount = new IdentityMsgAndFileCount(messageCount, fileCount); + data.put(uniqueName, identityMsgAndFileCount); } -// for(final Iterator<LocalIdentity> i = storageRoot.getLocalIdentities().iterator(); i.hasNext(); ) { -// final LocalIdentity id = i.next(); -// if( id == null ) { -// i.remove(); -// continue; -// } for( final LocalIdentity id : Core.getIdentities().getLocalIdentities() ) { - final int messageCount = MessageStorage.inst().getMessageCount(id.getUniqueName()); - final int fileCount = FileListStorage.inst().getFileCount(id.getUniqueName()); - final IdentityMsgAndFileCount s = new IdentityMsgAndFileCount(messageCount, fileCount); - data.put(id.getUniqueName(), s); + final String uniqueName = id.getUniqueName(); + final int messageCount = MessageStorage.inst().getMessageCount(uniqueName); + final int fileCount = FileListStorage.inst().getFileCount(uniqueName); + final IdentityMsgAndFileCount identityMsgAndFilecount = new IdentityMsgAndFileCount(messageCount, fileCount); + data.put(uniqueName, identityMsgAndFilecount); } return data; } @@ -289,18 +281,20 @@ int validEntries = 0; final List<Identity> lst = new ArrayList<Identity>(); + IPersistentList<Identity> identities = storageRoot.getIdentities(); + int numIdentities = identities.size(); - final int progressSteps = storageRoot.getIdentities().size() / 75; // all 'progressSteps' entries print one dot + final int progressSteps = numIdentities / 75; // all 'progressSteps' entries print one dot int progress = progressSteps; - for( int x=0; x < storageRoot.getIdentities().size(); x++ ) { + for( int x=0; x < numIdentities; x++ ) { if( x > progress ) { System.out.print('.'); progress += progressSteps; } Identity sfk; try { - sfk = storageRoot.getIdentities().get(x); + sfk = identities.get(x); } catch(final Throwable t) { brokenEntries++; continue; @@ -313,11 +307,11 @@ lst.add(sfk); } - storageRoot.getIdentities().clear(); + identities.clear(); commit(); for( final Identity sfk : lst ) { - storageRoot.getIdentities().add(sfk); + identities.add(sfk); } commit(); Modified: trunk/frost-wot/source/frost/storage/perst/messages/MessageStorage.java =================================================================== --- trunk/frost-wot/source/frost/storage/perst/messages/MessageStorage.java 2011-03-13 09:58:05 UTC (rev 3306) +++ trunk/frost-wot/source/frost/storage/perst/messages/MessageStorage.java 2011-03-13 10:47:19 UTC (rev 3307) @@ -113,16 +113,18 @@ } try { int highestBoardId = 0; + Index<PerstFrostBoardObject> boardsByName = storageRoot.getBoardsByName(); + Index<PerstFrostBoardObject> boardsById = storageRoot.getBoardsById(); for( final String boardName : boardPrimaryKeysByName.keySet() ) { final Integer boardId = boardPrimaryKeysByName.get(boardName); // prevent duplicate board names - if( storageRoot.getBoardsByName().contains(boardName) ) { + if( boardsByName.contains(boardName) ) { continue; // dup! } final PerstFrostBoardObject pfbo = new PerstFrostBoardObject(getStorage(), boardName, boardId.intValue()); - storageRoot.getBoardsByName().put(boardName, pfbo); - storageRoot.getBoardsById().put(boardId, pfbo); + boardsByName.put(boardName, pfbo); + boardsById.put(boardId, pfbo); highestBoardId = Math.max(highestBoardId, boardId.intValue()); } @@ -928,12 +930,13 @@ return 0; } try { + final Index<PerstFrostBoardObject> boardsByName = storageRoot.getBoardsByName(); for( final FrostMessageObject mo : msgObjects ) { if (mo.getPerstFrostMessageObject() == null || mo.getBoard() == null) { logger.severe("delete not possible"); continue; } - final PerstFrostBoardObject bo = storageRoot.getBoardsByName().get(mo.getBoard().getNameLowerCase()); + final PerstFrostBoardObject bo = boardsByName.get(mo.getBoard().getNameLowerCase()); if( bo == null ) { logger.severe("board not found"); continue; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |