'use strict';

var AMQPError = require('./amqp_error'),
    DeliveryStates = require('./delivery_state'),
    Source = require('./source_target').Source,
    Target = require('./source_target').Target,
    Message = require('./message');

function convertType(describedType) {
  var knownTypes = [
    AMQPError, Source, Target, DeliveryStates.Accepted, DeliveryStates.Received, DeliveryStates.Rejected, DeliveryStates.Released,
    Message.Header, Message.DeliveryAnnotations, Message.Annotations, Message.Properties, Message.ApplicationProperties,
    Message.Footer, Message.Data, Message.AMQPSequence, Message.AMQPValue
  ];
  var descriptorStr = describedType.descriptor.toString();
  for (var idx in knownTypes) {
    var curType = knownTypes[idx];
    if (curType.prototype.Descriptor.name.toString() === descriptorStr ||
        curType.prototype.Descriptor.code.toString() === descriptorStr) {
      return curType.fromDescribedType(describedType);
    }
  }

  return undefined;
}

module.exports = convertType;

@@ -236,48 +236,8 @@
 );%0A%0A
-function convertType(describedType) %7B%0A  
 var 
@@ -251,18 +251,16 @@
 pes = %5B%0A
-  
   AMQPEr
@@ -300,24 +300,26 @@
 es.Accepted,
+%0A 
  DeliverySta
@@ -382,18 +382,16 @@
 leased,%0A
-  
   Messag
@@ -441,32 +441,34 @@
 age.Annotations,
+%0A 
  Message.Propert
@@ -502,20 +502,16 @@
 perties,
-%0A   
  Message
@@ -518,16 +518,18 @@
 .Footer,
+%0A 
  Message
@@ -579,12 +579,49 @@
 lue%0A
-  
 %5D;
+%0A%0Afunction convertType(describedType) %7B
 %0A  v
@@ -682,88 +682,98 @@
 ;%0A  
-for (var idx in knownTypes) %7B%0A    var curType = knownTypes%5Bidx%5D;%0A    if (curType
+var _len = knownTypes.length;%0A  for (var _i = 0; _i %3C _len; ++_i) %7B%0A    if (knownTypes%5B_i%5D
 .pro
@@ -835,23 +835,30 @@
         
-curType
+knownTypes%5B_i%5D
 .prototy
@@ -925,15 +925,22 @@
 urn 
-curType
+knownTypes%5B_i%5D
 .fro

optimize loop for known types converter