SORU
18 Kasım 2014, Salı


Daha hızlı kod tamamlama çınlama ile

Olası kod tamamlama speedups çınlama kod tamamlama mekanizması kullanırken araştırıyorum. Akışı aşağıda belirtilen rtags tarafından bulunan Anders Bakken ne buldum.

Çeviri birimleri daemon dosyalarını izleyerek ayrıştırıldı. Bu clang_parseTranslationUnit denilen ve ilgili fonksiyonlar(reparse*, dispose*)tarafından yapılır. Ne zaman kullanıcı istekleri bitiminde belirli bir satır ve sütun içinde bir kaynak dosyası, daemon geçer önbelleğe alınan çeviri birim için en son kaydedilen sürümü kaynak dosyası ve geçerli bir kaynak dosyası için clang_codeCompleteAt. (Clang CodeComplete docs).

Bayrak clang_parseTranslationUnitgeçmiş (CompletionThread::process, line 271) CXTranslationUnit_PrecompiledPreamble|CXTranslationUnit_CacheCompletionResults|CXTranslationUnit_SkipFunctionBodes. Bayrak clang_codeCompleteAtgeçmiş (CompletionThread::process, line 305) CXCodeComplete_IncludeMacros|CXCodeComplete_IncludeCodePatterns.

Arama için clang_codeCompleteAt çok yavaş sürüyor etrafında 3-5 saniye elde etmek için tamamlanması hatta durumlarda nerede tamamlama konumu meşru bir üye erişim kodu, bir alt uygun olarak kullanılması durumunda anılan belgeleri clang_codeCompleteAt. Bu kod tamamlama standartları IDE çok yavaş görünüyor. Hız bir yolu var mı?

CEVAP
28 Mart 2011, PAZARTESİ


Geçtiğimiz hafta gremlin Bu da çalışma var.

Kabul edilen çözüm değişken genişlikli yazı tipleri için hesap ve wwwhack çözümü İse bir Döngü olduğundan, benim içine atacağım $.02.

Büyük ölçüde çapraz çarpım kullanarak benim sorunum işlem süresini azaltmak için mümkün oldu. Temel olarak, bu gibi görünen bir formül var:

enter image description here

Değişkenxçözmemiz gereken şey bu durumda. Bir Tamsayı olarak döndüğünde, üzerinden akan metin olması gerektiğini yeni uzunluğunu verecektir. 80% MaxLength elips göstermek için yeterli yer vermek için çarpılır.

Burada tam bir html örneği:

<html>
    <head>
        <!-- CSS setting the width of the DIV elements for the table columns.  Assume that these widths could change.  -->
        <style type="text/css">
            .div1 { overflow: hidden; white-space: nowrap; width: 80px; }
            .div2 { overflow: hidden; white-space: nowrap; width: 150px; }
            .div3 { overflow: hidden; white-space: nowrap; width: 70px; }
        </style>
        <!-- Make a call to Google jQuery to run the javascript below.  
             NOTE:  jQuery is NOT necessary for the ellipses javascript to work; including jQuery to make this example work -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {  
                //Loop through each DIV element
                $('div').each(function(index) {
                    var myDiv = this;  //The original Div element which will have a nodeType of 1 (e.g. ELEMENT_NODE)
                    var divText = myDiv; //Variable used to obtain the text from the DIV element above  

                    //Get the nodeType of 3 (e.g. TEXT_NODE) from the DIV element.  For this example, it will always be the firstChild  
                    divText = divText.firstChild;  

                    //Create another variable to hold the display text  
                    var sDisplayText = divText.nodeValue;  

                    //Determine if the DIV element is longer than it's supposed to be.
                    if (myDiv.scrollWidth > myDiv.offsetWidth) {  
                        //Percentage Factor is just a way of determining how much text should be removed to append the ellipses  
                        //With variable width fonts, there's no magic number, but 80%, should give you enough room
                        var percentageFactor = .8;  

                        //This is where the magic happens.
                        var sliceFactor = ((myDiv.offsetWidth * percentageFactor) * sDisplayText.length) / myDiv.scrollWidth;
                        sliceFactor = parseInt(sliceFactor);  //Get the value as an Integer
                        sDisplayText = sDisplayText.slice(0, sliceFactor)   "..."; //Append the ellipses
                        divText.nodeValue = sDisplayText; //Set the nodeValue of the Display Text
                    }
                });
            });
        </script>
    </head>
    <body>
        <table border="0">
            <tr>    
                <td><div class="div1">Short Value</div></td>    
                <td><div class="div2">The quick brown fox jumps over the lazy dog; lots and lots of times</div></td>    
                <td><div class="div3">Prince</div></td> 
            </tr>
            <tr>    
                <td><div class="div1">Longer Value</div></td>   
                <td><div class="div2">For score and seven year ago</div></td>   
                <td><div class="div3">Brown, James</div></td>   
            </tr>
            <tr>    
                <td><div class="div1">Even Long Td and Div Value</div></td> 
                <td><div class="div2">Once upon a time</div></td>   
                <td><div class="div3">Schwarzenegger, Arnold</div></td> 
            </tr>
        </table>
    </body>
</html>

Bu JS sadece bir düzeltme olduğunu biliyorum, ama Mozilla hata düzeltmeleri kadar, CSS bir çözüme ulaşmak için sadece yeterince akıllı değilim.

Bu örnek, JS her zaman bir kılavuz bizim uygulama yükler denir, çünkü en iyi benim için çalışıyor. Her tablo için sütun genişliği değişir ve ne tür bir bilgisayar üzerinde Firefox bizim kullanıcılar bizim app görünüm hiçbir kontrole sahip olan, tabii ki, bizolmamalıbu kontrol :) ).

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Benjamin Heckendorn

    Benjamin Hec

    4 Mayıs 2008
  • Defence Videos

    Defence Vide

    13 Mayıs 2013
  • Erica Griffin

    Erica Griffi

    8 HAZİRAN 2009