From 460f96967de6f5cb729ed57baaa4dad2178c8cb6 Mon Sep 17 00:00:00 2001 From: ACGNnsj Date: Tue, 28 Mar 2023 20:59:43 +0800 Subject: Slight Code Refactoring (#4373) * Simplify return statements by using ternary expressions * Remove a redundant type conversion * Reduce nesting by inverting "if" statements * Try to improve code readability by using LINQ and inverting "if" statements * Try to improve code readability by using LINQ, using ternary expressions, and inverting "if" statements * Add line breaks to long LINQ * Add line breaks to long LINQ --- .../Kernel/SyscallSyntaxReceiver.cs | 45 +++++++++++----------- 1 file changed, 22 insertions(+), 23 deletions(-) (limited to 'Ryujinx.Horizon.Kernel.Generators/Kernel/SyscallSyntaxReceiver.cs') diff --git a/Ryujinx.Horizon.Kernel.Generators/Kernel/SyscallSyntaxReceiver.cs b/Ryujinx.Horizon.Kernel.Generators/Kernel/SyscallSyntaxReceiver.cs index e2e8e1d3..e480a859 100644 --- a/Ryujinx.Horizon.Kernel.Generators/Kernel/SyscallSyntaxReceiver.cs +++ b/Ryujinx.Horizon.Kernel.Generators/Kernel/SyscallSyntaxReceiver.cs @@ -16,38 +16,37 @@ namespace Ryujinx.Horizon.Generators.Kernel public void OnVisitSyntaxNode(SyntaxNode syntaxNode) { - if (syntaxNode is ClassDeclarationSyntax classDeclaration && classDeclaration.AttributeLists.Count != 0) + if (!(syntaxNode is ClassDeclarationSyntax classDeclaration) || classDeclaration.AttributeLists.Count == 0) { - foreach (var attributeList in classDeclaration.AttributeLists) - { - if (attributeList.Attributes.Any(x => x.Name.GetText().ToString() == "SvcImpl")) - { - foreach (var memberDeclaration in classDeclaration.Members) - { - if (memberDeclaration is MethodDeclarationSyntax methodDeclaration) - { - VisitMethod(methodDeclaration); - } - } + return; + } + + if (!classDeclaration.AttributeLists.Any(attributeList => + attributeList.Attributes.Any(x => x.Name.GetText().ToString() == "SvcImpl"))) + { + return; + } - break; - } + foreach (var memberDeclaration in classDeclaration.Members) + { + if (memberDeclaration is MethodDeclarationSyntax methodDeclaration) + { + VisitMethod(methodDeclaration); } } } private void VisitMethod(MethodDeclarationSyntax methodDeclaration) { - if (methodDeclaration.AttributeLists.Count != 0) + if (methodDeclaration.AttributeLists.Count == 0) { - foreach (var attributeList in methodDeclaration.AttributeLists) - { - if (attributeList.Attributes.Any(x => x.Name.GetText().ToString() == "Svc")) - { - SvcImplementations.Add(methodDeclaration); - break; - } - } + return; + } + + if (methodDeclaration.AttributeLists.Any(attributeList => + attributeList.Attributes.Any(x => x.Name.GetText().ToString() == "Svc"))) + { + SvcImplementations.Add(methodDeclaration); } } } -- cgit v1.2.3