Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code optimization suggestions #756

Open
noobyu6 opened this issue Jun 7, 2022 · 1 comment
Open

Code optimization suggestions #756

noobyu6 opened this issue Jun 7, 2022 · 1 comment

Comments

@noobyu6
Copy link

noobyu6 commented Jun 7, 2022

Hi,

I find that the private field totalPages at Line 24 in the file 'shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/model/paging/PaginationData.java ' on the master branch is only assigned and used in the method setTotalPages. Therefore, this field can be removed from the class, and become a local variable in the method setTotalPages. This transformation will normally reduce memory usage and improve readability of your code.

private int totalPages; // line 24 this field can be replaced by local variable

public void setTotalPages(int totalPages) {
  	// int totalPages = totalPages
		this.totalPages = totalPages;
}

In addition, the private field name at Line 97 in the file 'shopizer/sm-core/src/main/java/com/salesmanager/core/business/services/reference/init/InitializationDatabaseImpl.java ' on the master branch is only assigned and used in the method EvolutionContextImpl. Therefore, this field can be removed from the class, and become a local variable in the method populate. Besides, for method createZones, createCurrencies, createMerchant, createSubReferences, createLanguages and createCountries, the field name can be converted to an input parameter.This transformation will normally reduce memory usage and improve readability of your code.I will be happy if this transformation is helpful.

private String name; // line 97 this field can be replaced by local variable

public void populate(String contextName) throws ServiceException {
		// 	String name = contextName
  	this.name =  contextName;
		
		createSecurityGroups();
  	// createLanguages(name)
		createLanguages();
  	// createCountries(name)
		createCountries();
  	// createZones(name)
		createZones();
  	// createCurrencies(name)
		createCurrencies();
  	// createSubReferences(name)
		createSubReferences();
		createModules();
  	// createMerchant(name)
		createMerchant();
	}
@srivishnu158
Copy link

Hi @noobyu6,

I've noticed that the totalPages variable is only being used once in the setTotalPages() method, which itself isn't being used anywhere. It seems that both the variable and the method have no real purpose since we neither have a getTotalPages() method nor a usage for this setTotalPages() method. Therefore, I believe both can be safely removed.

Additionally, I agree that the change you suggested for private String name reduces memory usage and improves readability.

I can work on these changes and submit a pull request if that works for everyone. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants