Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3988358
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:14:33+00:00 2026-05-20T06:14:33+00:00

Is it possible to optimize this code? I have very low performance on this

  • 0

Is it possible to optimize this code? I have very low performance on this keyup event.

$('#opis').keyup(function () {

  if ($('#opis').val() != "") {
    var search = $.grep(
    svgs, function (value) {
      reg = new RegExp('^' + $('#opis').val(), 'i');
      return value.match(reg) == null;
    }, true);
    $('#file_list').html("");
    var tohtml = "";

    $cnt = 0;
    for (var i = 0; i < search.length; i++) {
      if ($cnt <= 30) {
        tohtml += "<li class='file_item'><a href='' class='preview'>" + search[i] + "</a> <a href='" + search[i] + "' class='print_file'><img src='img/add16px.png' alt='dodaj'/></li></a>";
        $cnt++;
      } else {
        break;
      }
    }

    $('#file_list').html(tohtml);
    $(".preview").click(function () {
      $('#file_preview').html('<embed src="opisy/' + $(this).html() + '" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" /> ');
      $(".preview").parent().removeClass("selected");
      $(this).parent().addClass("selected");
      return false;
    });

    $(".print_file").click(function () {
      if (jQuery.inArray($(this).attr('href'), prints) == -1) {
        $('#print_list').append('<li>' + $(this).attr('href') + '</li>');
        prints.push($(this).attr('href'));
      } else {
        alert("Plik znajduje się już na liście do wydruku!");
      }
      return false;
    });
  } else {
    $('#file_list').html("  &nbsp;");
  }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:14:33+00:00Added an answer on May 20, 2026 at 6:14 am
    var opis = $('#opis')[0]; // this line can go outside of keyup  
    var search = [];
    var re = new RegExp('^' + opis.value, 'i');
    for (var i = 0, len = svgs.length; i < len; i++) {
        if (re.test(svgs[i])) {
            search.push(svgs[i]);
        }
    }
    

    It’s up to 100x faster in Google Chrome, 60x in IE 6.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can main function call itself in C++? I found this problem very
I am trying to optimize this query as good as possible,but still i am
I want to optimize this code: InputStream is = rp.getEntity().getContent(); BufferedReader reader = new
Please help me optimize/ refactor this code..... private sub test Call PopulateColorsWithMasterIdentity(Colors, Id) Call
Is it possible to good C compiler with high optimization enabled to optimize code
I have this specific function to extract parts of a list in the form:
So basically, besides possible performance effects, does inlining functions have any considerable effect on
Is it possible to optimize this kind of (matrix) algorithm: // | case 1
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.