Nikolay Sivov : dwrite: Use u32-reads for AnalyzeScript().

Alexandre Julliard julliard at winehq.org
Mon Jul 25 16:19:30 CDT 2022


Module: wine
Branch: master
Commit: dcb8094a37afb7bf505d4377158a5e0ce25bcd7c
URL:    https://gitlab.winehq.org/wine/wine/-/commit/dcb8094a37afb7bf505d4377158a5e0ce25bcd7c

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Mon Jul 25 12:34:58 2022 +0300

dwrite: Use u32-reads for AnalyzeScript().

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>

---

 dlls/dwrite/analyzer.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/dlls/dwrite/analyzer.c b/dlls/dwrite/analyzer.c
index 595d8806159..86d030b3738 100644
--- a/dlls/dwrite/analyzer.c
+++ b/dlls/dwrite/analyzer.c
@@ -513,22 +513,21 @@ static DWRITE_SCRIPT_ANALYSIS get_char_sa(WCHAR c)
     return sa;
 }
 
-static HRESULT analyze_script(const WCHAR *text, UINT32 position, UINT32 length, IDWriteTextAnalysisSink *sink)
+static HRESULT analyze_script(struct text_source_context *context, IDWriteTextAnalysisSink *sink)
 {
     DWRITE_SCRIPT_ANALYSIS sa;
-    UINT32 pos, i, seq_length;
+    UINT32 pos, seq_length;
 
-    if (!length)
-        return S_OK;
+    text_source_get_next_u32_char(context);
 
-    sa = get_char_sa(*text);
+    sa = get_char_sa(context->ch);
 
-    pos = position;
+    pos = context->position;
     seq_length = 1;
 
-    for (i = 1; i < length; i++)
+    while (!text_source_get_next_u32_char(context))
     {
-        DWRITE_SCRIPT_ANALYSIS cur_sa = get_char_sa(text[i]);
+        DWRITE_SCRIPT_ANALYSIS cur_sa = get_char_sa(context->ch);
 
         /* Unknown type is ignored when preceded or followed by another script */
         switch (sa.script) {
@@ -554,7 +553,7 @@ static HRESULT analyze_script(const WCHAR *text, UINT32 position, UINT32 length,
 
             hr = IDWriteTextAnalysisSink_SetScriptAnalysis(sink, pos, seq_length, &sa);
             if (FAILED(hr)) return hr;
-            pos = position + i;
+            pos += seq_length;
             seq_length = 1;
             sa = cur_sa;
         }
@@ -1104,23 +1103,17 @@ static HRESULT get_text_source_ptr(IDWriteTextAnalysisSource *source, UINT32 pos
 static HRESULT WINAPI dwritetextanalyzer_AnalyzeScript(IDWriteTextAnalyzer2 *iface,
     IDWriteTextAnalysisSource* source, UINT32 position, UINT32 length, IDWriteTextAnalysisSink* sink)
 {
-    WCHAR *buff = NULL;
-    const WCHAR *text;
+    struct text_source_context context;
     HRESULT hr;
 
     TRACE("%p, %u, %u, %p.\n", source, position, length, sink);
 
-    if (length == 0)
+    if (!length)
         return S_OK;
 
-    hr = get_text_source_ptr(source, position, length, &text, &buff);
-    if (FAILED(hr))
-        return hr;
-
-    hr = analyze_script(text, position, length, sink);
-    free(buff);
+    if (FAILED(hr = text_source_context_init(&context, source, position, length))) return hr;
 
-    return hr;
+    return analyze_script(&context, sink);
 }
 
 static HRESULT WINAPI dwritetextanalyzer_AnalyzeBidi(IDWriteTextAnalyzer2 *iface,




More information about the wine-cvs mailing list