From cd9e071098d0539dda3a4a5d3f45cfd8814de4ed Mon Sep 17 00:00:00 2001 From: Brian Carlstrom Date: Thu, 8 Jan 2015 08:24:06 -0800 Subject: Upgrade Proguard to 5.1. Downloaded from: http://sourceforge.net/projects/proguard/files/proguard/5.1/ Bug: 17550647 (cherry picked from commit 2270795fbe0b277bfd49f40950ecaa78583175cc) Change-Id: I4d4c6b4f11aca8d5595b7f285c675bc5873d5e24 --- .../classfile/editor/ComparableConstant.java | 77 +++++++++++++++------- 1 file changed, 52 insertions(+), 25 deletions(-) (limited to 'src/proguard/classfile/editor/ComparableConstant.java') diff --git a/src/proguard/classfile/editor/ComparableConstant.java b/src/proguard/classfile/editor/ComparableConstant.java index 476edd6..cd2a810 100644 --- a/src/proguard/classfile/editor/ComparableConstant.java +++ b/src/proguard/classfile/editor/ComparableConstant.java @@ -2,7 +2,7 @@ * ProGuard -- shrinking, optimization, obfuscation, and preverification * of Java bytecode. * - * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu) + * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free @@ -148,7 +148,7 @@ implements Comparable, ConstantVisitor } public void visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant) - { + { result = Double.compare(doubleConstant.getValue(), ((DoubleConstant)otherConstant).getValue()); } @@ -172,11 +172,10 @@ implements Comparable, ConstantVisitor result = index < otherIndex ? -1 : index > otherIndex ? 1 : - (invokeDynamicConstant.getName(clazz) + ' ' + - invokeDynamicConstant.getType(clazz)) - .compareTo - (otherInvokeDynamicConstant.getName(clazz) + ' ' + - otherInvokeDynamicConstant.getType(clazz)); + compare(invokeDynamicConstant.getName(clazz), + invokeDynamicConstant.getType(clazz), + otherInvokeDynamicConstant.getName(clazz), + otherInvokeDynamicConstant.getType(clazz)); } public void visitMethodHandleConstant(Clazz clazz, MethodHandleConstant methodHandleConstant) @@ -184,27 +183,27 @@ implements Comparable, ConstantVisitor MethodHandleConstant otherMethodHandleConstant = (MethodHandleConstant)otherConstant; int kind = methodHandleConstant.getReferenceKind(); - int otherKind = methodHandleConstant.getReferenceKind(); + int otherKind = otherMethodHandleConstant.getReferenceKind(); result = kind < otherKind ? -1 : kind > otherKind ? 1 : - (methodHandleConstant.getName(clazz) + ' ' + - methodHandleConstant.getType(clazz)) - .compareTo - (otherMethodHandleConstant.getName(clazz) + ' ' + - otherMethodHandleConstant.getType(clazz)); + compare(methodHandleConstant.getClassName(clazz), + methodHandleConstant.getName(clazz), + methodHandleConstant.getType(clazz), + otherMethodHandleConstant.getClassName(clazz), + otherMethodHandleConstant.getName(clazz), + otherMethodHandleConstant.getType(clazz)); } public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant) { RefConstant otherRefConstant = (RefConstant)otherConstant; - result = (refConstant.getClassName(clazz) + ' ' + - refConstant.getName(clazz) + ' ' + - refConstant.getType(clazz)) - .compareTo - (otherRefConstant.getClassName(clazz) + ' ' + - otherRefConstant.getName(clazz) + ' ' + - otherRefConstant.getType(clazz)); + result = compare(refConstant.getClassName(clazz), + refConstant.getName(clazz), + refConstant.getType(clazz), + otherRefConstant.getClassName(clazz), + otherRefConstant.getName(clazz), + otherRefConstant.getType(clazz)); } public void visitClassConstant(Clazz clazz, ClassConstant classConstant) @@ -223,11 +222,10 @@ implements Comparable, ConstantVisitor public void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant) { NameAndTypeConstant otherNameAndTypeConstant = (NameAndTypeConstant)otherConstant; - result = (nameAndTypeConstant.getName(clazz) + ' ' + - nameAndTypeConstant.getType(clazz)) - .compareTo - (otherNameAndTypeConstant.getName(clazz) + ' ' + - otherNameAndTypeConstant.getType(clazz)); + result = compare(nameAndTypeConstant.getName(clazz), + nameAndTypeConstant.getType(clazz), + otherNameAndTypeConstant.getName(clazz), + otherNameAndTypeConstant.getType(clazz)); } @@ -246,4 +244,33 @@ implements Comparable, ConstantVisitor { return this.getClass().hashCode(); } + + + // Small utility methods. + + /** + * Compares the given two pairs of strings. + */ + private int compare(String string1a, String string1b, + String string2a, String string2b) + { + int comparison; + return + (comparison = string1a.compareTo(string2a)) != 0 ? comparison : + string1b.compareTo(string2b); + } + + + /** + * Compares the given two triplets of strings. + */ + private int compare(String string1a, String string1b, String string1c, + String string2a, String string2b, String string2c) + { + int comparison; + return + (comparison = string1a.compareTo(string2a)) != 0 ? comparison : + (comparison = string1b.compareTo(string2b)) != 0 ? comparison : + string1c.compareTo(string2c); + } } -- cgit v1.2.3