Highlighted

ByteArray text find performance

New Here ,
Oct 12, 2018

Copy link to clipboard

Copied

Hi all~

I have an air app deal with the pixel level graphic, so I choose bdf font for text displaying. This font file is 7MB size and contains maybe 60k+ chars.

So my opinion simply is:

for each char I want to display at runtime,

get its charCode as an index,

find the charCode in bdf file,

then get the bits which make up the char.

And now, the problem is that the bdf file is huge. I use File::load() method to load the data into a byteArray, then find the charCode in it. I find it takes more than 5 secs to get the position for the last char in the file.

My find logic like this:

function search(findStr:String):uint {

  var basePos:uint = 0;

  var tempStr:String;

  while (basePos <= bdfFont.length) {

    bdfFont.position = basePos;

    try {

      tempStr = bdfFont.readUTFBytes(findStr.length);

    } catch(e:EOFError) {

      trace('didn\'t find');

      return;

    }

    if (tempStr == findStr) {

      trace('found:', basePos);

      return basePos;

    } else {

      basePos++;

    }

  }

}

So, how can I tweak my code to get better performance? Thanks!

TOPICS
Development

Views

119

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

ByteArray text find performance

New Here ,
Oct 12, 2018

Copy link to clipboard

Copied

Hi all~

I have an air app deal with the pixel level graphic, so I choose bdf font for text displaying. This font file is 7MB size and contains maybe 60k+ chars.

So my opinion simply is:

for each char I want to display at runtime,

get its charCode as an index,

find the charCode in bdf file,

then get the bits which make up the char.

And now, the problem is that the bdf file is huge. I use File::load() method to load the data into a byteArray, then find the charCode in it. I find it takes more than 5 secs to get the position for the last char in the file.

My find logic like this:

function search(findStr:String):uint {

  var basePos:uint = 0;

  var tempStr:String;

  while (basePos <= bdfFont.length) {

    bdfFont.position = basePos;

    try {

      tempStr = bdfFont.readUTFBytes(findStr.length);

    } catch(e:EOFError) {

      trace('didn\'t find');

      return;

    }

    if (tempStr == findStr) {

      trace('found:', basePos);

      return basePos;

    } else {

      basePos++;

    }

  }

}

So, how can I tweak my code to get better performance? Thanks!

TOPICS
Development

Views

120

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 12, 2018 0

Have something to add?

Join the conversation