Skip to content

Commit

Permalink
added aggressive parallelization to find_unused
Browse files Browse the repository at this point in the history
  • Loading branch information
silverweed committed Dec 19, 2014
1 parent 1c7d3de commit a6b5419
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions data/find_unused.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,35 @@
# Finds unused classes with a stupid, flawed and inefficient algorithm
# author Giacomo Parolini

while [[ $# > 0 ]]; do
case $1 in
-p) PAR=true; QUIET=true; shift ;;
*) echo "Usage: $0 [-p]"; exit 0 ;;
esac
done

BASE=$(dirname $(readlink -f $0))/..
check_class() {
CLASS="$1"
while read FILE; do
OUT=$(while read FILE; do
egrep "[ \t]*${CLASS}\.?" $FILE | \
sed -rn -e 's/[^:]*:(.*)/\1/p' -e '/^\s*\/[/*]/ !{p}' -e 's/^\s*(.*)/\1/p' -e '/^\s*$/ !{p}'
done < <(find $BASE -name \*java | grep -v unused | grep -v $CLASS)
done < <(find $BASE -name \*java | grep -v unused | grep -v $CLASS))
[[ $OUT ]] || echo $CLASS may be unused.
}

while read PACKAGE CLASS; do
PACKAGE=${PACKAGE/data\/\.\.\//}
# don't consider classes in the following packages
[[ ${PACKAGE%animation/} != $PACKAGE ]] && continue

echo CHECKING $CLASS >&2
[[ $QUIET ]] || echo Checking $CLASS ... >&2

if [[ ! $(check_class $CLASS) ]]; then
echo ---\> $CLASS may be unused.
if [[ $PAR ]]; then
# your processor won't easily forgive you.
check_class $CLASS &
else
check_class $CLASS
fi

done < <(find $BASE -regextype posix-extended -regex '.*(battle|gui|net|player|enums|util|sound).*java' | perl -lne 'print "$1 $2" if /(.*\/)*(.*)\.java/')

0 comments on commit a6b5419

Please sign in to comment.