Repository: nvaccess/nvda

Issue:
winVersion.isWin10: modify it to return early if major is not 10
Hi,

This feature request should not be done for 2019.3 in order to avoid introducing possible regressions, but perhaps defer it to 2020.1:

### Is your feature request related to a problem? Please describe.
In NVDA 2019.2, as part of UIA console support, winVersion module introduced isWin10 function which returns whether a system is running a specific version of Windows 10 or later. At the moment it checks major version in two places:

* If "at least" flag is specified: return False if version is less than 10.
* If "at least" flag is not specified: return False if major version is not 10.

At least it is understandable. But I would argue that for sake of performance and keeping the subject line and body in sync, I propose the below modification.

### Describe the solution you'd like
Instead of checking flags after defining version information map, return early if major version isn't even 10. Not only flag checks can be avoided on Windows 8.1 and earlier, it can make the function body in line with what the function title says.

Thus I propose:

1. First, check winVersion.major and return False if it isn't 10.
2. Define version to build map.
3. Same as current function.

### Describe alternatives you've considered
Keep the function as is.

### Additional context
I'm sure there might be other opportunities to optimize this function, but that's in the future.

Thanks.


Discussion:
CC @codeofdusk 

Resolving patch:
diff --git a/source/winVersion.py b/source/winVersion.py
--- a/source/winVersion.py
+++ b/source/winVersion.py
@@ -26,34 +26,35 @@ def canRunVc2010Builds():
 def isUwpOcrAvailable():
 	return os.path.isdir(UWP_OCR_DATA_PATH)
 
-def isWin10(version=1507, atLeast=True):
+
+WIN10_VERSIONS_TO_BUILDS = {
+	1507: 10240,
+	1511: 10586,
+	1607: 14393,
+	1703: 15063,
+	1709: 16299,
+	1803: 17134,
+	1809: 17763,
+	1903: 18362,
+	1909: 18363,
+}
+
+
+def isWin10(version: int = 1507, atLeast: bool = True):
 	"""
 	Returns True if NVDA is running on the supplied release version of Windows 10. If no argument is supplied, returns True for all public Windows 10 releases.
 	@param version: a release version of Windows 10 (such as 1903).
 	@param atLeast: return True if NVDA is running on at least this Windows 10 build (i.e. this version or higher).
 	"""
-	from logHandler import log
-	win10VersionsToBuilds={
-		1507: 10240,
-		1511: 10586,
-		1607: 14393,
-		1703: 15063,
-		1709: 16299,
-		1803: 17134,
-		1809: 17763,
-		1903: 18362,
-		1909: 18363,
-	}
-	if atLeast and winVersion.major < 10:
-		return False
-	elif not atLeast and winVersion.major != 10:
+	if winVersion.major != 10:
 		return False
 	try:
 		if atLeast:
-			return winVersion.build >= win10VersionsToBuilds[version]
+			return winVersion.build >= WIN10_VERSIONS_TO_BUILDS[version]
 		else:
-			return winVersion.build == win10VersionsToBuilds[version]
+			return winVersion.build == WIN10_VERSIONS_TO_BUILDS[version]
 	except KeyError:
+		from logHandler import log
 		log.error("Unknown Windows 10 version {}".format(version))
 		return False
 


Test patch: