Index: trunk/src/VBox/Devices/EFI/DevEFI.cpp
===================================================================
--- trunk/src/VBox/Devices/EFI/DevEFI.cpp	(revision 44608)
+++ trunk/src/VBox/Devices/EFI/DevEFI.cpp	(revision 44609)
@@ -284,22 +284,38 @@
 {
     LogFlowFunc(("%RTuuid::'%s'\n", pUuid, pszVariableName));
-
-    int      rc         = VERR_NOT_FOUND;
-    uint32_t cVariables = 0;
-    PEFIVAR  pEfiVar;
-    RTListForEach(&pThis->NVRAM.VarList, pEfiVar, EFIVAR, ListNode)
-    {
-        LogFlowFunc(("pEfiVar:%p\n", pEfiVar));
-        cVariables++;
-        if (   pEfiVar
-            && RTUuidCompare(pUuid, &pEfiVar->uuid) == 0
-            && RTStrCmp(pszVariableName, pEfiVar->szName) == 0) /** @todo case sensitive or insensitive? */
+    size_t const    cchVariableName = strlen(pszVariableName);
+    int             rc              = VERR_NOT_FOUND;
+
+    /*
+     * Start by checking the last variable queried.
+     */
+    if (   pThis->NVRAM.pCurVar
+        && pThis->NVRAM.pCurVar->cchName == cchVariableName
+        && memcmp(pThis->NVRAM.pCurVar->szName, pszVariableName, cchVariableName + 1) == 0
+        && RTUuidCompare(&pThis->NVRAM.pCurVar->uuid, pUuid) == 0
+        )
+    {
+        *ppEfiVar = pThis->NVRAM.pCurVar;
+        rc = VINF_SUCCESS;
+    }
+    else
+    {
+        /*
+         * Linear list search.
+         */
+        PEFIVAR pEfiVar;
+        RTListForEach(&pThis->NVRAM.VarList, pEfiVar, EFIVAR, ListNode)
         {
-            *ppEfiVar = pEfiVar;
-            rc = VINF_SUCCESS;
-            break;
+            Assert(strlen(pEfiVar->szName) == pEfiVar->cchName);
+            if (   pEfiVar->cchName == cchVariableName
+                && memcmp(pEfiVar->szName, pszVariableName, cchVariableName + 1) == 0
+                && RTUuidCompare(&pEfiVar->uuid, pUuid) == 0)
+            {
+                *ppEfiVar = pEfiVar;
+                rc = VINF_SUCCESS;
+                break;
+            }
         }
     }
-    Assert(pThis->NVRAM.cVariables >= cVariables);
 
     LogFlowFunc(("rc=%Rrc pEfiVar=%p\n", rc, *ppEfiVar));
@@ -435,6 +451,5 @@
 static int nvramWriteVariableOpQuery(PDEVEFI pThis)
 {
-    LogRel(("EFI: Querying Variable %RTuuid::'%s'\n",
-            &pThis->NVRAM.VarOpBuf.uuid, pThis->NVRAM.VarOpBuf.szName));
+    Log(("EFI_VARIABLE_OP_QUERY: %RTuuid::'%s'\n", &pThis->NVRAM.VarOpBuf.uuid, pThis->NVRAM.VarOpBuf.szName));
 
     PEFIVAR pEfiVar;
@@ -457,5 +472,5 @@
 static int nvramWriteVariableOpQueryNext(PDEVEFI pThis)
 {
-    Log(("EFI: Querying next variable...\n"));
+    Log(("EFI_VARIABLE_OP_QUERY_NEXT: pCurVar=%p\n", pThis->NVRAM.pCurVar));
     PEFIVAR pEfiVar = pThis->NVRAM.pCurVar;
     if (pEfiVar)
@@ -475,7 +490,7 @@
 static int nvramWriteVariableOpAdd(PDEVEFI pThis)
 {
-    LogRel(("EFI: Adding variable %RTuuid::'%s'\n", &pThis->NVRAM.VarOpBuf.uuid, pThis->NVRAM.VarOpBuf.szName));
-    LogFlowFunc(("fAttributes=%#x abValue=%.*Rhxs\n", pThis->NVRAM.VarOpBuf.fAttributes,
-                 pThis->NVRAM.VarOpBuf.cbValue, pThis->NVRAM.VarOpBuf.abValue));
+    LogRel(("EFI_VARIABLE_OP_ADD: %RTuuid::'%s' fAttributes=%#x abValue=%.*Rhxs\n",
+            &pThis->NVRAM.VarOpBuf.uuid, pThis->NVRAM.VarOpBuf.szName, pThis->NVRAM.VarOpBuf.fAttributes,
+            pThis->NVRAM.VarOpBuf.cbValue, pThis->NVRAM.VarOpBuf.abValue));
 
     /*
@@ -516,5 +531,5 @@
              * Delete it.
              */
-            LogFlow(("nvramWriteVariableOpAdd: Delete\n"));
+            LogRel(("EFI: Deleting variable %RTuuid::'%s'\n", &pThis->NVRAM.VarOpBuf.uuid, pThis->NVRAM.VarOpBuf.szName));
             RTListNodeRemove(&pEfiVar->ListNode);
             pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
@@ -531,5 +546,6 @@
              * Update/replace it. (The name and UUID are unchanged, of course.)
              */
-            LogFlow(("nvramWriteVariableOpAdd: Replace\n"));
+            LogRel(("EFI: Replacing variable %RTuuid::'%s' fAttrib=%#x cbValue=%#x\n", &pThis->NVRAM.VarOpBuf.uuid,
+                    pThis->NVRAM.VarOpBuf.szName, pThis->NVRAM.VarOpBuf.fAttributes, pThis->NVRAM.VarOpBuf.cbValue));
             pEfiVar->fAttributes   = pThis->NVRAM.VarOpBuf.fAttributes;
             pEfiVar->cbValue       = pThis->NVRAM.VarOpBuf.cbValue;
@@ -549,5 +565,6 @@
          * Add a new variable.
          */
-        LogFlow(("nvramWriteVariableOpAdd: New\n"));
+        LogRel(("EFI: Adding variable %RTuuid::'%s' fAttrib=%#x cbValue=%#x\n", &pThis->NVRAM.VarOpBuf.uuid,
+                pThis->NVRAM.VarOpBuf.szName, pThis->NVRAM.VarOpBuf.fAttributes, pThis->NVRAM.VarOpBuf.cbValue));
         pEfiVar = (PEFIVAR)RTMemAllocZ(sizeof(EFIVAR));
         if (pEfiVar)
@@ -574,5 +591,6 @@
         static unsigned s_cWarnings = 0;
         if (s_cWarnings++ < 5)
-            LogRel(("EFI: Too many variables.\n"));
+            LogRel(("EFI: Too many variables (%RTuuid::'%s' fAttrib=%#x cbValue=%#x)\n", &pThis->NVRAM.VarOpBuf.uuid,
+                    pThis->NVRAM.VarOpBuf.szName, pThis->NVRAM.VarOpBuf.fAttributes, pThis->NVRAM.VarOpBuf.cbValue));
         pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
         Log(("nvramWriteVariableOpAdd: Too many variabled.\n"));
@@ -608,5 +626,6 @@
                 case EFI_VARIABLE_OP_QUERY_REWIND:
                     Log2(("EFI_VARIABLE_OP_QUERY_REWIND\n"));
-                    pThis->NVRAM.pCurVar = NULL;
+                    pThis->NVRAM.pCurVar   = NULL;
+                    pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
                     break;
 
