Uploaded image for project: 'Apache Flex'
  1. Apache Flex
  2. FLEX-23962

UITextField - method truncateToFit() causes CPU overload

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • Adobe Flex SDK 3.4 (Release)
    • Adobe Flex SDK Next
    • mx: Label
    • None
    • Affected OS(s): All OS Platforms
      Affected OS(s): All OS Platforms
      Language Found: English

    Description

      Steps to reproduce:
      1. Create a label and set this label to a certain width (100px p.e) and set the truncateToFit=true
      2. When the text for the label as a textWidth of 8000 px, p.e,
      3. Since the function truncateToFit() start from the last position to the first, 1 char by 1 char then this will cause a great CPU load.

      Actual Results:
      When we have a DataGrid with a text(in the condition explained above) to truncate on some columns, the cpu will suffer a great load and the application will misfunction for some moments after this.

      Expected Results:
      There should be a better algorithm to perform such a ( possibly) heavy operation

      Possible solution:
      We can make some changes in the function so that when it is better to start from position 0 to the last that fit then we perform the algorithm this way instead of always start by the last position.
      We have to extend the UITextField and perform an override to the truncateToFit() and change the code where we perform the slice to:
      var TEXT_WIDTH_PADDING:int = 5;
      // Need to check if we should truncate, but it
      // could be due to rounding error. Let's check that it's not.
      // Examples of rounding errors happen with "South Africa" and "Game"
      // with verdana.ttf.
      if (originalText != "" && textWidth + TEXT_WIDTH_PADDING > w + 0.00000000000001)
      {
      // This should get us into the ballpark.
      var s:String=super.text=originalText;
      originalText.slice(0, Math.floor((w / (textWidth + TEXT_WIDTH_PADDING)) * originalText.length));

      //if the TextWidth is bigger than 2 * width of the space for it ,
      //it is best to go from the start
      if(textWidth + TEXT_WIDTH_PADDING > 2 * w){
      var i:int = 0;
      super.text = truncationIndicator;
      while (textWidth + 15 < w) //i put 15 px so that the truncateIndicator can fit when starting from the begining

      { s = originalText.substring(0, i); super.text = s + truncationIndicator; i++; }

      }
      else{ //if the TextWidth is less than 2 * width it is best to go from the end
      while (s.length > 1 && textWidth + TEXT_WIDTH_PADDING > w)

      { s=s.slice(0, -1); super.text=s + truncationIndicator; }

      }
      return true;
      }

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            adobejira Adobe JIRA
            adobejira Adobe JIRA
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment